Page 1 of 1

spliting search results 10 by 10

Posted: Sat Oct 21, 2006 12:00 pm
by pedrotuga
This might been asked like dozens of times, though i performed a searched and didnt find so much.

i want to perform a search in a database and then show the results 10 each time, like google and friends do.

Thats ok, i limit the result, make pagination etc etc...

now my biggest issue is performance.

like... if perform a search that returns 10000 results, 10000 row will be selected.
Is there any way i can get the number of matches without slow down the whole thing?

thanks in advance.

Posted: Sat Oct 21, 2006 12:12 pm
by nickvd
Gets the first 10 entries:

Code: Select all

SELECT * FROM BLAH LIMIT 0,10
Gets the Next 10 entries:

Code: Select all

SELECT * FROM BLAH LIMIT 10,10

Posted: Sat Oct 21, 2006 1:05 pm
by Chris Corbyn
The trickiest thing is know how many pages you have in total so that you know the upper boundary for your LIMIT.

I tend to run a very bare bones COUNT(*) query which I test to return the same number of records as the real query before-hand. I then can use this value to generate the page list. I'm sure there are better ways but you need to know how many records you have before you can make one of those lists.

Posted: Sun Oct 22, 2006 3:37 pm
by pedrotuga
a count... didnt thought about that... sounds quicker than a select.

i think it should do it...

let me perform some tests.