The title is a bit wonky but it's the best I could come up with at 4 in the morn'. I have a table of links that I am paginating, nothing fancy. Let's say there are 100 links that are displayed 20 a page for 5 pages. How can I number each link starting with 1 and ending with 20 on the first page and if we skipped to the last page would be 81 through 100. I have multiple queries changing the direction and ORDER BY of my queries so this would have to be dynamically. Done using CakePHP 1.2. An example of this would be reddit.com
2条回答 默认 最新
- duanruanxian5028 2009-09-02 09:22关注
Try this in the view:
<?php debug($this->params['paging']); ?>
This'll give you a bit of inside information about the current status of the paginator. For example, you'll find this:
Array ( [Model] => Array ( [page] => 2 ... [options] => Array ( [limit] => 20 ...
'limit'
being the "items per page" and'page'
being, well, the page.
With this information it should be pretty trivial to insert this kind of counter into your output.$page = $this->params['paging']['Model']['page']; $limit = $this->params['paging']['Model']['options']['limit']; $counter = ($page * $limit) - $limit + 1; foreach ($models as $model) { echo $counter; // normal $model output $counter++; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 DS18B20内部ADC模数转换器
- ¥15 做个有关计算的小程序
- ¥15 MPI读取tif文件无法正常给各进程分配路径
- ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
- ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
- ¥15 setInterval 页面闪烁,怎么解决
- ¥15 如何让企业微信机器人实现消息汇总整合
- ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
- ¥15 如何用Python爬取各高校教师公开的教育和工作经历
- ¥15 TLE9879QXA40 电机驱动