Re: Too many records to display in one web page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The way I handle it:

Step 1-
Add SELECT SQL_CALC_FOUND_ROWS to the front of your initial query and add 
the pagination limit to the end (LIMIT 200, 400 or whatever range you want 
to display.)

Step 2-
Do a 2nd query: SELECT FOUND_ROWS() immediately after.

What does this do?

It will return your record set within the limit range specified. However 
SQL_CALC_FOUND_ROWS also allows you to calculate how many total rows you 
would return if you had no limit. By running SELECT FOUND_ROWS() it will 
give you the total number of rows in the query. So for instance in the 
pseudo query above, mysql_num_rows would only return 200 on the query but 
SELECT FOUND_ROWS() might return 2000 if that's how many rows the query 
would return.

Now you can use math to determine how many total pages you will have, what 
page you are on, etc so you can tweak the pagination to whatever suits your 
needs.

""Eduardo Vizcarra"" <evizcarra@xxxxxxxx> wrote in message 
news:26.38.49291.220C8564@xxxxxxxxxxxxxxx
> Hi All
>
> I am developing a web site that interacts with a MySQL database. When I 
> run a query and display the records in a web page, this can become a 
> problem because there might be too many records to be displayed in one 
> single web page so I am trying to divide the total number of records and 
> display them in multiple pages. Let's say, if the query returns 100 
> records then I would like to display the first 10 records and then put a 
> navigation bar where I can go to the next 10 or return to the previous 10 
> records
>
> Is this done at a SQL or PHP level ? any experience on doing this ?
>
> Thanks a bunch
> Eduardo 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux