Skip site navigation (1) Skip section navigation (2)

Re: Pagination of search results

From: <dculotta(at)fibertel(dot)com(dot)ar>
To: Neil Saunders <n(dot)j(dot)saunders(at)gmail(dot)com>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: Pagination of search results
Date: 2005-11-23 16:34:43
Message-ID: b593667e63b0.43846ff3@fibertel.com.ar (view raw or flat)
Thread:
Lists: pgsql-php
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 <n(dot)j(dot)saunders(at)gmail(dot)com>
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 <LOTS OF CLAUSES>) AS c WHERE
> <SAME LOT OF CLAUSES> 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
> 


pgsql-php by date

Next:From: Keary SuskaDate: 2005-11-23 21:06:32
Subject: Re: Pagination of search results
Previous:From: Neil SaundersDate: 2005-11-23 16:14:16
Subject: Pagination of search results

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group