我正在使用 Codeigniter 分页库,
我想知道如何获取使用分页类显示的第一个和最后一个项目的数量?
所以,如果我有 12 个结果,并且 per_page 设置为 5。我想要
Page 1: Displaying 1 to 5 of 12 results
第2页:Displaying 6 to 10 of 12 results
第 3 页:Displaying 11 to 12 of 12 results
.
保持简单。
你需要3个变量。结果开始、结果结束(在页面中,而不是整个结果)和总结果。
您已经知道总结果(来自分页)。我们就这样称呼它吧$total
.
-
所以,现在获取当前页面($curpage
) 来自 CI 实例的值。然后,
$result_start = ($curpage - 1) * $per_page + 1;
if ($result_start == 0) $result_start= 1; // *it happens only for the first run*
-
for $result_end
,您只需添加每页值,但考虑到它会少 1,
$result_end = $result_start+$per_page-1;
if ($result_end < $per_page) // happens when records less than per page
$result_end = $per_page;
else if ($result_end > $total) // happens when result end is greater than total records
$result_end = $total;
-
发送所有这 3 个值进行查看。
echo "displaying $result_start to $result_end of $total";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)