Etienne Marais
Etienne Marais

Reputation: 1690

Whats the formula to get the page numbers for pagination?

This question is relevant for a lightweight pagination script I am busy writing.

I have the total items and the page limit for every page. for example 15 items in total but I would like to paginate on 10. This means there are 2 pages. How do I get to that using a formula?

I am using ceil( $total / $page_limit ) at the moment is that right?

Upvotes: 2

Views: 6736

Answers (4)

D K Gupta
D K Gupta

Reputation: 1

If you find proper solution of the pagination then you can use this

TotalPage=(TotalRecords/PageSize)+((TotalRecords%PageSize)>0)?1:0)

Upvotes: 0

Rizwan Yahya
Rizwan Yahya

Reputation: 350

I am not sure where you are at the moment with a code, but you need to do little more to create a pagination process, i would suggest to google some simple php pagination code and use that in your code.

check this one for help! http://php.about.com/od/phpwithmysql/ss/php_pagination.htm

Upvotes: 1

knittl
knittl

Reputation: 265291

yes, it's right. 15/10 = 1.5. that ceiled is 2

Upvotes: 4

Berry Langerak
Berry Langerak

Reputation: 18859

I am using ceil( $total / $page_limit ) at the moment is that right?

Yes, it is. If there is nothing to round (e.g. if the outcome is not a float) it will simply return the outcome. If the outcome is a float, it will round it up (next highest integer value), so you'll have one page with less items than the rest, but that shouldn't be an issue.

Upvotes: 3

Related Questions