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 DD963DBD62 for ; Sat, 26 Nov 2005 22:10:35 -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 45688-06 for ; Sun, 27 Nov 2005 02:10:38 +0000 (GMT) X-Greylist: delayed 03:13:56.342959 by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by svr1.postgresql.org (Postfix) with ESMTP id 4927DDA806 for ; Sat, 26 Nov 2005 22:10:33 -0400 (AST) Received: from swordfish.dnsvelocity.com (swordfish.dnsvelocity.com [209.123.180.114]) by svr2.postgresql.org (Postfix) with ESMTP id 8A4CAF0BB5 for ; Sat, 26 Nov 2005 22:56:38 +0000 (GMT) Received: from s0106000f660223be.vc.shawcable.net ([24.83.99.55] helo=chris) by swordfish.dnsvelocity.com with esmtpa (Exim 4.52) id 1Eg8y2-0006Os-UZ; Sat, 26 Nov 2005 22:56:27 +0000 Message-ID: <000a01c5f2dc$a3bfa560$6501a8c0@chris> From: "Cstdenis" To: "Neil Saunders" , References: Subject: Re: Pagination of search results Date: Sat, 26 Nov 2005 00:59:53 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-PopBeforeSMTPSenders: cstdenis+voicio.com X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - swordfish.dnsvelocity.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - voicio.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.881 required=5 tests=[DATE_IN_PAST_12_24=0.881] X-Spam-Score: 0.881 X-Spam-Level: X-Archive-Number: 200511/28 X-Sequence-Number: 3345 Get the count once and store it in a session. ----- Original Message ----- From: "Neil Saunders" To: Sent: Wednesday, November 23, 2005 8:14 AM Subject: [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