TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   pagination question (http://www.talkphp.com/absolute-beginners/3988-pagination-question.html)

sarmenhb 02-19-2009 09:26 PM

pagination question
 
why is it no matter how hard i try the switch in my head wont go on when i try to study and understand how pagination works?

i keep trying to ask my self how the formulas were figured out and stuff like that

my head starts to to hurt lol

am i the only one? lol

xenon 02-19-2009 11:44 PM

Where are you having problems? To determine how many pages you need, you need 2 variables: the total number of "items" (be it entries in a database or just some records in an array), and the number of "items" you wish to display on a page. The number of resulting pages will be total_number_of_items / number_of_items_per_page. It's just simple math...nothing complicated.

Here's a simple hands-on example:

PHP Code:

$items range(125);
$items_per_page 10;

$number_of_items count($items);
$total_pages ceil($number_of_items $items_per_page); // we use ceil because if we have 11 entries, with 10 entries per page, that means there will be 2 pages

echo $total_pages// this will give 3 


Tanax 02-19-2009 11:50 PM

I had a hard time myself before. Then I created my own independant paginationclass(meaning it isn't locked to pagination of dbresults, but it can paginate anything), and once I saw - and worked with - the formulas, it all became clear.

You should read it and see if anything becomes clearer.
http://www.talkphp.com/script-giveaw...ion-class.html


All times are GMT. The time now is 03:28 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0