views:

76

answers:

3

Hi,

I have an SQL query that returns an amount of tuples (about 50). Now I need to display the results, 15 tuples at a time, then I will have a "view more" button to view the next 15 results.

Can you please help me how I can make this? The issue is that I cannot use the 'limits' because each time I run the query the results will be different, hence when pressing view more, I may get the same results of the same page.

thanks

+1  A: 

If you can't use LIMIT, this means your script will have to fetch and load the 50 tuples. If you only want to display 15, you should look for a Javascript solution to hide the others and only show the active ones.

The JQuery Datatables is an EXCELLENT piece of work. You just load all the tuples in a table, and call the Datatable - that's it! You can later customize it to show more or less than 15 at a time.

Konerak
thanks for the tip! :0)
mouthpiec
I've already upvoted this, but I want to just say I can't recommend this solution enough.
Weston C
+1  A: 

Instead of reloading, you should put each "page" into a display:hidden div and using JS you show one div after another.

Lo'oris
Depending on the row size of the result, this is sometimes a bad idea. Whether its hidden or not, 1000 (for example) rows can add a lot of DOM nodes, increasing page load time and decreasing responsiveness.
Justin Johnson
Sure! But if he says the query results will change at every invocation, I see no other logically possible solution.
Lo'oris
the number of rows should be around 100 ....
mouthpiec
It's the better, and afaik only, method. Just use it, and start to worry only if you have problems, not before (when you likely won't have problems anyway).
Lo'oris
A: 

If you can only run the query once, you only have two options:

  • Send the entire resultset to the browser, hiding all but 15 rows. "View more" would simply unhide more rows.

  • Run the query once and cache the results, but only send back the rows requested to the browser. When more rows are requested from the browser, send back another set of cached rows. This is useful for progressively loading large or complex data sets.

Matt S