X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B37D3DBA55 for ; Wed, 23 Nov 2005 12:34:54 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36561-04 for ; Wed, 23 Nov 2005 16:34:52 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from avas-mr12.fibertel.com.ar (avas-mr12.fibertel.com.ar [24.232.0.225]) by svr1.postgresql.org (Postfix) with ESMTP id 94913DBA48 for ; Wed, 23 Nov 2005 12:34:51 -0400 (AST) Received: from [10.10.10.228] ([10.10.10.228]:59940 "EHLO fibertel.com.ar" smtp-auth: ) by avas-mr12.fibertel.com.ar with ESMTP id S262343AbVKWQeo convert rfc822-to-8bit; Wed, 23 Nov 2005 13:34:44 -0300 Received: from [10.10.10.172] (Forwarded-For: [200.47.6.109]) by stov2.fibertel.com.ar (mshttpd); Wed, 23 Nov 2005 13:34:43 -0300 From: To: Neil Saunders Cc: pgsql-php@postgresql.org Message-ID: Date: Wed, 23 Nov 2005 13:34:43 -0300 X-Mailer: Sun Java(tm) System Messenger Express 6.1 HotFix 0.11 (built Jan 28 2005) MIME-Version: 1.0 Content-Language: es Subject: Re: Pagination of search results X-Accept-Language: es Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8BIT X-Fib-Al-Info: Al X-Fib-Al-MRId: 41d0b1573ff1ae1abe70c89ec7c3b6a5 X-Fib-Al-From: dculotta@fibertel.com.ar X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.886 required=5 tests=[AWL=-0.583, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44, NO_REAL_NAME=0.55] X-Spam-Score: 1.886 X-Spam-Level: * X-Archive-Number: 200511/24 X-Sequence-Number: 3341 I think that this is the way. You need at first time know the number of recrods at first, then you need that's records to show. ----- Mensaje original ----- De: Neil Saunders Fecha: Miércoles, Noviembre 23, 2005 1:14 pm Asunto: [PHP] Pagination of search results > Hi, > > I'm writing a search engine, the results of which will displayed in > blocks of 25, paginated. I will also display the number of records > found (1-25 of 345). > > I'm trying to determine the most efficient way to implement this. > Since the session is dropped after the script is terminated, I'm > ruling our cursors. Also, cursors would prevent me from retrieving the > total number of records potentially returned from a search, and so I > couldn't display the correct number of page links. Also, this would > require persistent connections, which I'd like to avoid for a number > of reasons. > > The best I've come up with is "SELECT b.*, c.cnt FROM table AS b, > (SELECT COUNT(1) AS cnt FROM table WHERE ) AS c WHERE > LIMIT 25 OFFSET 0" > > However this means that the query is essentially getting executed > twice for each page. > > Is there any better way of implementing this? All advice gratefully > received. > Kind Regards, > > Neil Saunders. > > ---------------------------(end of broadcast)----------------------- > ---- > TIP 6: explain analyze is your friend >