突出显示当前页码PHP分页 [英] Highlight Current page number PHP Pagination
问题描述
我在解决此问题时遇到问题,因此我需要更专业的解决方案.我的产品列表中有分页设置.问题是当我切换页面时,编号上的活动班级没有显示或显示有误.例如,当用户单击2(第2页)时,它显示项目的第二页,而突出显示的是5.需要帮助解决此问题,以突出显示当前正在查看的页面.
I'm having problems resolving this so I'm asking for more professional solutions. I have pagination setup for my list of products. Problem is when I switch pages, the active class on the number is not showing or showing wrongly. For example, when users click on 2 (Page 2), it displays the 2nd page of items, but 5 is the one highlighted. Need help fixing this up to highlight the currently being viewed page.
此代码用于设置偏移量.
This code is for setting the offset.
$totalrows = db_getvalue("select count(buyinfo_id) from buyinfo,user $addtable where buyinfo.user_id=user.user_id $clause $orderbyclause", $global_connection);
if ($totalrows == "")
$totalrows = 0;
$totalpages = ceil($totalrows/$listcount);
if ($totalpages > 1) {
$curpageoffset = 0;
if (isset($_REQUEST['offset'])) {
if ($_REQUEST['offset'] >= $totalpages)
$curpageoffset = $totalpages - 1;
else if ($_REQUEST['offset']>0)
$curpageoffset = $_REQUEST['offset']*$listcount-1;
}
$limitstr = " limit $curpageoffset,$listcount";
}
例如,当我转到第3页时,它将显示www.site.com/?offset=2
When I go to Page 3 for example, it displays www.site.com/?offset=2
我猜这是因为$ curpageoffset = $ _REQUEST ['offset'] * $ listcount-1; -1;
I guess its because of the -1 in $curpageoffset = $_REQUEST['offset']*$listcount-1;
这是负责页码的代码:
<?php
if ($totalpages>1) {
echo "<tr><td><ul class='pagination'>";
echo "<li><a href='' aria-label='Previous' ";
if ($curpageoffset == 0) {
echo "onclick='return false;'";
} else {
echo "onclick='util_reload(\"posts/?offset=".($curpageoffset-1)."$pageparam\"); return false;'";
}
echo " ><span aria-hidden='true'>«</span></a></li>";
$tmpctr = 0;
while ($tmpctr < $totalpages) {
$curstyle = "";
if ($tmpctr == $curpageoffset)
$curstyle = "class='active'";
echo "<li $curstyle><a href='' onclick='util_reload(\"posts/?offset=$tmpctr$pageparam\"); return false;'>";
$tmpctr++;
echo "$tmpctr</a></li>";
}
echo "<li><a href='' aria-label='Next' ";
if ($curpageoffset >= $totalpages-1) {
echo "onclick='return false;'";
} else {
echo "onclick='util_reload(\"posts/?offset=".($curpageoffset+1)."$pageparam\"); return false;'";
}
echo " ><span aria-hidden='true'>»</span></a></li>";
echo "</ul></td></tr>";
}
?>
推荐答案
由于您已设置了curpageoffset的值以供查询使用,因此您无法在分页代码中使用它来突出显示当前所在的页面...我将以这种方式更改您的代码..使用原始的$ _REQUEST ['offset'],因为这实际上是页码.
Since you've set the value of curpageoffset for use in your query, you can't use it in your pagination code to highlight the page you're on ... I would change your code this way .. using the original $_REQUEST['offset'] since that's essentially the page number.
while ($tmpctr < $totalpages) {
$curstyle = "";
if ($tmpctr == $_REQUEST['offset'])
$curstyle = "class='active'";
echo "<li $curstyle><a href='' onclick='util_reload(\"posts/?offset=$tmpctr$pageparam\"); return false;'>";
$tmpctr++;
echo "$tmpctr</a></li>";
}
这篇关于突出显示当前页码PHP分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!