限制分页页码
2022-08-30 22:56:27
$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);
这是我用于创建用于数据搜索的分页页的代码。但我刚刚注意到我有太多的记录,那么它将有太多的页码。我试图限制显示的页码,并寻找许多例子.它有很多方法可以做到这一点,但我仍然不知道如何限制它为我的方法...