$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("Test");
$strSQL = "SELECT * FROM UserAddedRecord WHERE (Name LIKE '%".$getname."%' and State LIKE '%".$getstate."%' and Cell LIKE '%".$getcell."%' and Custgroup LIKE '%".$getgroup."%') AND user_id=$id";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 5;
if (!isset($_GET['Page'])) {
$Page = 1;
} else {
$Page = $_GET['Page'];
}
$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;
$Page_Start = (($Per_Page * $Page) - $Per_Page);
if ($Num_Rows <= $Per_Page) {
$Num_Pages = 1;
} elseif (($Num_Rows % $Per_Page) == 0) {
$Num_Pages = ($Num_Rows / $Per_Page) ;
} else {
$Num_Pages = ($Num_Rows / $Per_Page) + 1;
$Num_Pages = (int) $Num_Pages;
}
$strSQL .=" order by addedrec_ID DESC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL) or trigger_error(mysql_error());;
if ($Prev_Page) {
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'><< Back</a> ";
}
for ($i=1; $i <= $Num_Pages; $i++) {
if ($i != $Page) {
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$i&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'>$i</a> ";
} else {
echo "<b> $i </b>";
}
}
if ($Page!=$Num_Pages) {
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtName=$getname&txtState=$getstate&txtCell=$getcell&txtGroup=$getgroup'>Next>></a> ";
}
mysql_close($objConnect);
This is the code I use to create pagination page for data search.But I just noticed that I have too many records then it will have too many page numbers.I'm trying to limit the page number shown,and look for many examples ..it have many ways to do it but I still don't have idea how to limit it for my method...