Page 1 of 1

PHP MySql and limiting results

Posted: Tue Jun 11, 2002 11:22 am
by bopritchard
I've got a page that has sql that returns x number of rows...i only want to display 10 per page....and then have a Page 1, 2, 3 etc link....i know i can limit the records returned by doing limit 10 or limit 5, 10 at the end of my sql....but what about knowing how many i've got total so that i know how many page links i need to display...

for instance if i've got 47 total records i want to display Page 1,2,3,4,5 as links to forward through the results....i know i can do a select count(*) from xxxx.....but i'm sure there is another way another than performing and additional query....

and what about the php code to handle those page numbers...anyone got an example i can look at...

thanks

Database pagination

Posted: Wed Jun 12, 2002 1:31 pm
by BDKR
This is a common asked question. There is a tutorail on the topic at PHPBUILDER. There should still be one or two over at phpdeveloper.org as well.

I really say you should give it a stab yourself as it will make you a better coder. The big things you need is the limit clause in MySQL (or SQL in general), count() or mysqll_num_rows() (assumint you are using mysql) depending on whether or not you want to get the row count via MySQL or PHP, and then some simple math to figure out what rows are going to be shown on what pages.

To use your example, if there are 47 records and you want to show 5 records at a time, then we allready know how many pages we are going to need right? Ten! You get my drift.

Later on,
BDKR (TR Cox)

Posted: Wed Jun 12, 2002 9:27 pm
by chris12295
haha, i have just finished overcoming that dilema myself. email me if you want a full description of what i did. chris12295@aol.com. :P

GREAT!

Posted: Thu Jun 13, 2002 11:12 am
by BDKR
Right on! I will email you as a matter of fact.

I'm glald to hear,
Later on,
BDKR (TR Cox)