Storing arrays in session variables

I have written a routine to handle pagination of a query result set. Currently, I am storing the viewed block number as a session variable and running the query each time they want another page of results.

In a real world environment, is it okay to store the query result set in a session array variable so it doesn’t need to be run each time or is this too much overhead for the server? Assume it’s a fairly sizable result set since it involves showing only 10 or so rows at a time.

This is not so much a technical question as it is a best practices question so anything you can add regarding actual experience would be greatly appreciated.

Thanks

wow, very cool. Thanks

A little off your questions, but in the past I have had a lot of fun dealing with pagination issues using JV Multimedia’s ‘EZ Results Pagination Class’. Here’s a link:

http://is.gd/d6wIX

Have fun coding whatever you do!

Why, yes, yes you do. :cool:


SELECT stuff FROM table LIMIT 21, 9

Thanks for the insight. I do appreciate it. I’m sure both of you understand how daunting learning a new technology can be on it’s own, but it’s the best practices and implementation that really get you. This help is invaluable.

Anthony, when you use the phrase “multiple tabs” what do you mean?

Why would you want to store the query results?
The only way this would be worthwhile is if the user wanted to view ALL (or nearly all) the records in a single visit; and if you were going to do that, you could just use javascript to ‘paginate’ the entire set on one page.
The idea behind pagination is (beyond simple aesthetics) that using the paginated (or alpha-indexed, or whatever) links a user can reach the specific subset of results quickly, and reduces load on the server by not needing to retrieve the undesired entries.

StarLion, to make sure I understand, I am talking about a situation where the query returns 150 rows and I want to show 10 at a time so the user can just click next to page through the rows. But that is not limiting the query in any way. I have no way to write a query that says just give me rows 21 thru 30 do I?

So you are saying I should return all 150 rows (or however many there are, there could be 1500) to the page and handle the pagination at the client level with javascript? Thanks

I’m going to agree with Jake, how would multiple tabs cope with this? I’ll save you the bother, not very well. :wink:

I really wouldn’t recommend storing such a large item in sessions.

The query alone each page would be more efficient, and space considerations; imagine, say, 5000 hits a day, that’s going to be 5000 large arrays stored as sessions in files on your server - that’s a fair lot of server use for something like this!