Fetching 10 rows is much faster than 1000 ! Fourat your code is optimized just keep it as it :) just keep your code away from adodb, pear db, and such abstraction if you want speed ! you don't need to talk about optimisation with 2 queries. Regards, Hatem --- "Patel, Aman" <Aman.Patel@xxxxxxxxxx> wrote: > I've run in to this situation before. And it turns > out that the extra > pre-"count" query is not worth it. So the steps > become: > > 1) Do your main query and fetch the results. > 2) Use the count of results obtained in step 1. > 3) Calculate pagination numbers. > 4) Use array_slice to limit the results to a page > window calculated in > step 3. > > Hope this helps. > > - Aman Patel, Sys Admin / Database / Web Developer, > International > Outreach x4076 > > > -----Original Message----- > > From: Zouari Fourat [mailto:fourat@xxxxxxxxx] > > Sent: Tuesday, March 22, 2005 10:03 AM > > To: php-db@xxxxxxxxxxxxx > > Subject: Re: paginating : optimising > queries > > > > > > no one can help me outta here ? > > > > > > On Mon, 21 Mar 2005 01:58:10 +0100, Zouari Fourat > > <fourat@xxxxxxxxx> wrote: > > > Hello, > > > i made my own paginating class, it permit me to > paginate > > over selected > > > data and let me do good presentation (page 1, > page 2 ...) i > > use adodb > > > for db related functions, my application should > show in every page > > > this set of informations : > > > > > > Total results : Z, Total page : Y, You are on > the page number X. > > > > > > To show thos informations, i must do a count on > all the > > table, example > > > : the query built from the form submitted by the > user is : > > > > > > select * from table where column=value and > column like 'value%' > > > > > > to paginate that query, i'll add some LIMIT or > LIMIT OFFSET > > for pgsql > > > (it's adodb frontend) so i'll get only the data > for one > > page ! i use > > > this query : > > > > > > select count(*) from table > > > > > > with that global count i can calculate how much > pages i have by > > > dividing count on the number of rows to show per > page. > > > > > > with this method, the server will suffer for big > tables... it's a > > > method that i've made without consulting what > people do, can you do > > > this with only ONE query so i can optimise ? > > > > > > thank you for your help > > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: > http://www.php.net/unsub.php > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails ! Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php