Re: [PHP-DB] Displaying next ten items

2006-12-28 Thread Darryl Ware



Ron Piggott (PHP) wrote:

I am wondering what the mySQL commands are to display the next 10
records / previous 10 records.  


I am wondering how you pass a variable through a PHP script so the
script knows which next or previous 10 entries to display.  (Especially
since this is all variable driven)  Would you do something like ?next=21
and ?previous=1 as part of the URL link to know where your query should
begin?  I do know the LIMIT = mySQL command to limit 10 items to be
displayed.

How do you tell when there aren't 10 more entries left to display?  IE
If there are 46 records in a table and you are displaying 40 to 46 you
don't want to offer a link to display records 50 to 59.  


Ron



Hi Ron,

To display a range in mysql you can simply use the 'limit' parameter.

eg: select * from table limit 100,10

I would normally just pass the offset through the get var.

You don't have to worry if there aren't 10 left to display as limit will 
just return the rows that are left.


For complete non results (like record 59 of 46) there are a few schools 
of though, like doing a max/min on the id field or a row count to see 
whats the possible range.


Darryl.

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



[PHP-DB] Re: 10 rows

2006-12-28 Thread Darryl Ware

Ron Piggott (PHP) wrote:

I would normally just pass the offset through the get var.


I understand what you are saying in concept ... but what would a 
sample command be like?


a href=http://www.host.com/script.php?next=21 
http://www.host.com/script.php?next=11Next Link/a
a href=http://www.host.com/script.php?previous=1 
http://www.host.com/script.php?next=11Previous Link/a


Ron 
How you pass it is incidental really, the variable name is only for your 
benefit, so these are as valid as the next way of doing it.


To learn more you may want to google for pagination php  and that will 
put you onto plenty of great tutorials.


Darryl.

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