Re: I'm using DB and wonder how can I EASILY add results paging without changing my code much?
| From: | Matthew Weier O'Phinney | Date: | Fri, 31 Dec 2004 12:55:14 +0000 |
| Subject: | Re: I'm using DB and wonder how can I EASILY add results paging without changing my code much? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16536@lists.php.net to get a copy of this message | ||
* l Burnerheimerton <lburnerheimerton@yahoo.com>:
> Below is some code. I need to add apging to this page since it could
> list many items.
>
> $res =& $db->query("SELECT ID, fName FROM names WHERE ID = 1
> if (DB::isError($res)) {
> die($res->getMessage());
> }
>
> while($row =& $res->fetchRow()) {
> echo "<tr><a
> href=\"op.php?i=$row[0]\">$row[1]</a></tr>";
> }
>
>
> Any ideas or code or links to read are much appreciated!
First off, you're going to need to use limits in your sql statements.
Then, you're going to need to have some code that determines what page
you're on in order to determine the offset for your limit. If you look
at the PEAR::Pager docs, I think you'll get the idea. This stuff is
simply not as trivial as a one line change to your script -- but it is
possible and relatively easy.
--
Matthew Weier O'Phinney | mailto:matthew@garden.org
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org