October 12th, 2000, 06:00 AM
I've got a search facility that interrogates an SQL database then shows the results 30 at a time. Currently, when you go to the next page of results it has to run the query all over again, because there is no way of handing the resultset to the PHP file. So I wondered if there was another way of doing it.
I'm tempted to use mysql_fetch_array and create a multi-dimensional array full of result rows, then hand that around, but so far cannot find out how to hand a PHP array as a variable to a PHP page.
IS this possible, or am I barking up the wrong tree? Or is there a better way of doing this?
October 12th, 2000, 06:44 AM
You COULD do it using a POST method (I imagine that the result set would be to large to use GET.) However, I wouldn't recommend it. If you're result set contains 300 records (10 pages at 30/page) and each has 5 fields of an avg 30 bytes each, that's 45KB of information you'll be passing back and forth to the client each time you go to a new page. And you can't just drop viewed information because you might need to re-generate a previous page. If you are developing for a broadband intranet or otherwise KNOW that all users will be using broadband, then this is no problem. HOwever, for a typical web page, a 28.8K user will experience a delay of about 20 seconds for each page request just to pass this large result set each way!
If your query is extremely complex with several joins and conditionals, you MIGHT save some time by storing it in a temporary table. If it's a simple query you're much better off just doing the query for each new page.
October 12th, 2000, 07:46 AM
It's a good point, and one I had not considered simply because it IS on a broadband intranet. However, a resultset of 300 would actually be somewhat on the small side for most querys on this database, so I'd be carting much more than 45Kb at a time. Good job you brought it up.
Do you know if it's possible to POST the result from an SQL query to another page? Or does the resultset get dropped the when you close the database?
October 12th, 2000, 11:55 AM
What we were talking about was the result set. I think you mean the result index? In that case, no. The result set the result index points to ceases to exist when the script ends.
How often would the data change? I mean, you could run a cron job to generate static HTML pages from the query and only run it periodically.