TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-19-2009, 09:26 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default 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
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 02-19-2009, 11:44 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 02-19-2009, 11:50 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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.
Pagination class
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Advance Pagination Class Rendair Advanced PHP Programming 13 02-01-2013 11:08 AM
Pagination class Tanax Script Giveaway 21 01-29-2013 12:38 PM
Pagination Or Something Else? Randy General 4 10-22-2012 09:32 AM
$_SERVER['REQUEST_URI'] question solistus General 4 04-01-2008 09:31 PM
Important Database Structure Question! AnthonyOS MySQL & Databases 5 12-20-2007 03:26 PM


All times are GMT. The time now is 01:38 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design