Hai*_*ood 2 php pagination codeigniter
我是,使用Codeigniter分页库,
我想知道如何使用分页类获取显示的第一个和最后一个项目的数量?
所以,如果我有12个结果,并且per_page设置为5.我希望
第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实例获取当前page()值.然后,
$result_start = ($curpage - 1) * $per_page + 1;
if ($result_start == 0) $result_start= 1; // *it happens only for the first run*
Run Code Online (Sandbox Code Playgroud)因为$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;
Run Code Online (Sandbox Code Playgroud)发送所有这3个值进行查看.
echo "displaying $result_start to $result_end of $total";
Run Code Online (Sandbox Code Playgroud)