X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id C7CF5D1B53A for ; Wed, 13 Aug 2003 23:09:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 77664-09 for ; Wed, 13 Aug 2003 20:08:04 -0300 (ADT) Received: from smtp.electroniccity.org (smtp.electroniccity.org [207.219.15.18]) by svr1.postgresql.org (Postfix) with ESMTP id DD190D1B52C for ; Wed, 13 Aug 2003 20:09:27 -0300 (ADT) Received: from [172.16.2.153] (d2-153.electroniccity.org [172.16.2.153]) by smtp.electroniccity.org (Postfix) with ESMTP id 7890DDF209; Wed, 13 Aug 2003 19:02:41 -0500 (EST) User-Agent: Microsoft-Outlook-Express-Macintosh-Edition/5.02.2022 Date: Wed, 13 Aug 2003 19:12:43 -0400 Subject: Re: Paging results From: Lynna Landstreet To: =?ISO-8859-1?B?wg==?=ngelo Marcos Rigo , Message-ID: In-Reply-To: <20030811173147.77918.qmail@web14808.mail.yahoo.com> Mime-version: 1.0 Content-type: text/plain; charset="ISO-8859-1" Content-transfer-encoding: quoted-printable X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/54 X-Sequence-Number: 2231 on 8/11/03 1:31 PM, =C2ngelo Marcos Rigo at angelo_rigo@yahoo.com.br wrote: > I have this script (please adapt the section where the > results are showed) Thank you very much - I've implemented this on one of my results pages as a test, and it seems to be partially working - the results are limited properly, and there are no errors, but the next and previous links aren't quite working right. On the first page, the prev link points to offset 0 and page 1, which I guess is correct, but the next link leaves offset blank, and has page 0, instead of having offset 50 (that's what I set $limit to) and page 2 as I would think it should. If I enter those values manually in the URL - http://www.gallery44.org/db/artists_browse_paged.php?offset=3D50&pgnum=3D2 = - the second page displays correctly, but again the prev and next links don't work right. The prev page here shows pgnum=3D1, which is correct, but it shows offset as 30 when it should be 50. And the next link shows exactly what it did on page 1 - offset=3D&pgnum=3D0. I've looked at the code, but I don't t= hink I'm following it well enough to be sure what's going wrong. I've attached a copy of the file=20 I kept the code pretty much as it was except for the part where the results are displayed, and a couple of very minor tweaks (changed the pg_query and pg_num_rows to pg_exec and pg_numrows because I'm using PHP 4.1, changed the part where it selects the whole table and uses pg_numrows to count it to a select count because it seemed more efficient, and changed $conn to the database connection I'd already opened, $db). If you or anyone else could suggest what might be going wrong, I'd very much appreciate it. Here's what I've got: First part (before displaying query results): // Paging script - request for parameters. $offset =3D $_REQUEST['offset']; $pgnum =3D $_REQUEST['pgnum']; =20=20=20=20 // Make that they are integer - security. settype($offset, 'integer'); settype($pgnum, 'integer'); =20=20=20=20 // Open database, i.e PostgreSQL if (!$db) { echo "An error occured - no database connection exists.\n"; exit;=20 }=20 =20=20=20=20 // Initialize variables. $limit=3D50; // rows to return $numresults=3Dpg_exec("SELECT COUNT(*) FROM artists"); //PostgreSQL // $numrows=3Dpg_numrows($numresults); =20=20=20=20 // next determine if offset has been passed to script, if not use 0 if (empty($offset)) { $offset=3D0;=20 $pgnum=3D1;=20 }=20 Then comes the display of the results, which is working fine. Second part: // calculate number of pages needing links $pages=3Dintval($numrows/$limit); =20=20=20=20 // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { =20=20=20=20=20=20=20=20 // has remainder so add one page $pages++; }=20 =20=20=20=20 echo "\n

"; // next we need to do the links to other results if (pages!=3D1) {=20 if ($pgnum=3D=3D1) { print "PREV   \n";=20 }=20 else=20 {=20 $prevoffset=3D$offset-20; $cpgnum =3D intval($prevoffset/$limit)+1; print "PREV   \= n"; }=20 }=20 =20=20=20=20 for ($i=3D1;$i<=3D$pages;$i++) { // loop thru $newoffset=3D$limit*($i-1); $cpgnum =3D $i; print "$cpgnum  = \n"; }=20 =20=20=20=20 // check to see if last page if ($pages!=3D1) {=20 if ($pgnum<$pages) { $newoffset=3D$offset+$limit; $cpgnum =3D intval(($offset+$limit)/$limit)+1; print "NEXT

\n"; =20=20=20=20 }=20 else=20 {=20 print "NEXT

\n"; =20=20=20=20 }=20 }=20 Many thanks, Lynna --=20 Resource Centre Database Coordinator Gallery 44 www.gallery44.org