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 1D501D1C513 for ; Mon, 11 Aug 2003 17:32:00 +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 16872-07 for ; Mon, 11 Aug 2003 14:30:29 -0300 (ADT) Received: from web14803.mail.yahoo.com (web14803.mail.yahoo.com [216.136.224.219]) by svr1.postgresql.org (Postfix) with SMTP id 5D6C1D1C4DB for ; Mon, 11 Aug 2003 14:31:48 -0300 (ADT) Message-ID: <20030811173148.66610.qmail@web14803.mail.yahoo.com> Received: from [200.219.69.252] by web14803.mail.yahoo.com via HTTP; Mon, 11 Aug 2003 14:31:48 ART Date: Mon, 11 Aug 2003 14:31:48 -0300 (ART) From: =?iso-8859-1?q?=C2ngelo=20Marcos=20Rigo?= Subject: Re: Paging results To: David Busby , Lynna Landstreet , pgsql-php@postgresql.org In-Reply-To: <001301c35df8$4a5123d0$1100000a@busbydev> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/36 X-Sequence-Number: 2213 I have this script (please adapt the section where the results are showed)
"; echo ""; echo ""; echo ""; echo ""; while ($row = pg_fetch_array($result, $i)) { echo ""; */ echo "$row[$j]"; //echo " $j['autor']"; } echo ""; //echo "
"; } echo "
AutorTitulo
"; //$arr = pg_fetch_array($result,($i)); for ($j=0; $j < count($row); $j++) { /* echo "
"; echo "$row[$j] "; echo "
"; // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } echo ""; // next we need to do the links to other results if (pages!=1) { if ($pgnum==1) { print "PREV   \n"; } else { $prevoffset=$offset-20; $cpgnum = intval($prevoffset/$limit)+1; print "PREV   \n"; } } for ($i=1;$i<=$pages;$i++) { // loop thru $newoffset=$limit*($i-1); $cpgnum = $i; print "$cpgnum   \n"; } // check to see if last page if ($pages!=1) { if ($pgnum<$pages) { $newoffset=$offset+$limit; $cpgnum = intval(($offset+$limit)/$limit)+1; print "NEXT

\n"; } else { print "NEXT

\n"; } } // Close database. pg_close($conn); ?> --- David Busby escreveu: > Paging with PostgreSQL is super easy! > select * from table where (x=y) offset 0 limit 30; > Gives you the first 30 matches, then do > select * from table where (x=y) offset 30 limit > 30; > This will give the next 30, super easy! > > Here's a sample of how I use it in a script > > // Collect offset > $offset = isset($_GET['offset'])?$_GET['offset']:0; > // Now the links for Prev/Next > if ($offset >= 30) echo "| href='/contents.php?".$qs."offset=".($offset-30)."'>Back > 30"; > echo "| href='/contents.php?".$qs."offset=".($offset+30)."'>Next > 30"; > // Query > $rs = pg_exec($db,"select id,name from stuff order > by name offset $offset > limit 30;"); > > /B > > > ----- Original Message ----- > From: "Lynna Landstreet" > To: > Sent: Friday, August 08, 2003 13:30 > Subject: [PHP] Paging results > > > > HI there, > > > > Thanks to everyone who helped with my keyword > problem - I think I thanked > > them all individually but I thought I should > mention it here too. > > > > Now, a new question: > > > > Does anyone know if there's a PHP class anywhere > out there for paging > > results from a PostgreSQL query, similar to > Paginator or ezResults which > do > > that for MySQL? Or do I have to do the code for > that from scratch? > > > > Alternatively, would it be difficult to adapt one > of those to working with > > PostgreSQL instead of MySQL? > > > > > > Lynna > > -- > > Resource Centre Database Coordinator > > Gallery 44 > > www.gallery44.org > > > > > > ---------------------------(end of > broadcast)--------------------------- > > TIP 1: subscribe and unsubscribe commands go to > majordomo@postgresql.org > > > ---------------------------(end of > broadcast)--------------------------- > TIP 8: explain analyze is your friend ===== Ângelo Marcos Rigo AMR Informática (51) 3348 0870 Rua Pe. Alois Kades 400/210 Porto Alegre /RS/Brasil http://amr.freezope.org angelo_rigo@yahoo.com.br _______________________________________________________________________ Conheça o novo Cadê? - Mais rápido, mais fácil e mais preciso. Toda a web, 42 milhões de páginas brasileiras e nova busca por imagens! http://www.cade.com.br