计算分页的项目偏移量 [英] Calculating item offset for pagination

查看:96
本文介绍了计算分页的项目偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是非常简单的数学,但是不知何故,我的大脑无法思考...

this seems like very simple maths but somehow, my brain cant think ...

我正在尝试实现分页,并且需要计算项偏移量以用于限制我的结果集.我在计算页面的第一项应该具有的索引时遇到问题.

i am trying to implement pagination and will need to calculate the item offset to use in limiting my result set. i am having problems calculating what index the first item of the page should have.

例如

with 1 page having 10 items

page 1 will have items 1 - 10
page 2 ............... 11 - 20
page 3 ............... 21 - 30

我想到了

offset = page * itemsPerPage + 1

但第1页不是这种情况.为此必须有一个公式吗?我正在使用PHP/Zend_Paginator/Doctrine2,但这应该与语言无关

but this will not be the case for page 1. there must be a formula for this? am using PHP/Zend_Paginator/Doctrine2 but this should be language independent

想知道这是否应该在数学堆栈交换站点中

推荐答案

使用offset = (page - 1) * itemsPerPage + 1.

这篇关于计算分页的项目偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆