Use session variables or multiple sql queries?
Posted: Sun Nov 26, 2006 8:00 pm
I am writing a script to search a database I have put together. There will potentially be thousands of records. If someone did a rather broad search, there could be 2,000 to 3,000 matching records. The results will be displayed 15 per page. The search window allows the user to define up to 5 different fields. As an example, if we are talking about cars - the user can define:
location of car (by state)
model of car
price of car
color of car
year of car
* some fields allow multiple selections (such as year, color, model, location) *
Which of the following options am I better of implementing in terms of site performance (assuming that traffic will be around 1,000 unique visitors per day).
1) A user enters a search. I save the results of the search in various session variables (arrays). As the user browses through each page, I access the the arrays as needed. So for the second page I display (again, assuming I am displaying 15 records per page) the index I will need to use to extract the array information is 15 - 29 (i.e. $_SESSION['car_name'][29]; ).
2) For each page that is displayed, perform a new SQL query. The limits in the query would change depending on the page number I am looking at. For the second page of search results I would set the limit to 16 - 30.
Bottom line - should I perform a bunch of SQL statements frequently, or - do the query once and store it as a session variable. Any thoughts you can offer on this would be appreciated.
location of car (by state)
model of car
price of car
color of car
year of car
* some fields allow multiple selections (such as year, color, model, location) *
Which of the following options am I better of implementing in terms of site performance (assuming that traffic will be around 1,000 unique visitors per day).
1) A user enters a search. I save the results of the search in various session variables (arrays). As the user browses through each page, I access the the arrays as needed. So for the second page I display (again, assuming I am displaying 15 records per page) the index I will need to use to extract the array information is 15 - 29 (i.e. $_SESSION['car_name'][29]; ).
2) For each page that is displayed, perform a new SQL query. The limits in the query would change depending on the page number I am looking at. For the second page of search results I would set the limit to 16 - 30.
Bottom line - should I perform a bunch of SQL statements frequently, or - do the query once and store it as a session variable. Any thoughts you can offer on this would be appreciated.