RE: [PHP] using LIMIT
| From: | Tom Walsh | Date: | Wed, 30 Aug 2000 16:08:17 +0000 |
| Subject: | RE: [PHP] using LIMIT | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-14424@lists.php.net to get a copy of this message | ||
Actually the correct syntax is:
LIMIT $offset, $number_of_records_to_return
So:
SELECT * FROM mydb WHERE name = 'John' LIMIT 20, 10
will return 10 users with name John starting from the 20th time John is
found... So in theory it would give you records 21-30... Now if you want to
do a listing of pages (Previous 10 and Next 10) you would do something like:
$query = "SELECT * FROM $usertable LIMIT $offset, 10";
$result = MYSQL_QUERY($query);
$next = $offset + 10;
$previous = $offset - 10;
{blah}
<A HREF=view.php?offset=$previous>Click here to see the previous 10
records</A>
<A HREF=view.php?offset=$next>Click here to see the next 10 records</A>
And just FYI this info is covered at MySQL.com HOWEVER... Their
documentation is terrible when you compare it to what PHP offers so I can't
blame you for asking here.
Tom Walsh
http://www.designgeek.com
> can anyone point me to some code on using LIMIT to make my
> data set smaller.
>
> THanks,
> Chuck
>