Re: pass a $result from a mysql_query in a url



JRough wrote:
On Nov 11, 7:32 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
JRough wrote:
I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$result);
but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];
I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.
I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,
$result is only a resource - in this case, a reference to data still
stored in MySQL. The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@xxxxxxxxxxxxx
==================

So you are saying that it is less memory intensive to requery the
database than to pass the result of a query?

First of all, don't get into premature optimization. If you have a problem, then - and only then - is the time to look at optimizing your code. Rather, code for clarity.

As for which is more "memory intensive" - there is no answer to that. Passing it in a post variable means the data has to make 2 trips - server to client, then back to server. If you've got 20 bytes of data, that isn't bad. But 20MB would be terrible.

Additionally, the data could be modified by a hacker - which may or may not be a problem for you. But it can happen (to any data coming from the client).

The $_SESSION superglobal array is much more secure, since it never leaves the server. But serializing and deserializing large amounts of data here also can be slow.

Finally, if you do pass the data, one way or another, what's to say the data hasn't been changed? The user might have gone to get a cup of coffee, for instance, and then come back and continued. In the meantime, someone else changed the data he was looking at. So when he gets to the next page, the data is old.

For these reasons and more, when you're working with a database, it's often better just to fetch the data on the new page. And if the query is the same (and follows pretty closely in time), the data is probably still going to be in the database cache, so retrieval will be quite fast.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: MailMerge hangs and crashes with Access on Server
    ... Since I am fairly new to working in this environment, I am not sure what you mean by an "Access group" with help to restructuring the query? ... "Peter Jamieson" wrote: ... All I know is that the performance of queries depends to a large extent on whether, for example, a join is performed on the client side, or on the server side, incurring no network traffic and potentially benefitting from caching on the server. ... There are no dialog boxes, and actually, I have now split the database, and have kept the Word templates and the Access frontend locally on my machine, and moved the backend to the server. ...
    (microsoft.public.word.mailmerge.fields)
  • Re: MailMerge hangs and crashes with Access on Server
    ... restructuring a complex query. ... discards 99% of them), or on the server side, incurring no network ... the database is locked and Word will not open the data source. ... have kept the Word templates and the Access frontend locally on my machine, ...
    (microsoft.public.word.mailmerge.fields)
  • Re: MailMerge hangs and crashes with Access on Server
    ... I have mapped out the path to the final query that is used to get to the ... the database is locked and Word will not open the data source. ... have kept the Word templates and the Access frontend locally on my machine, ... and moved the backend to the server. ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Single-Threading / Performance issues
    ... SQL Server MVP ... > Early this year my database was migrated from a single CPU, ... (when a long select query is running, ... server guy also sez it's not his problem. ...
    (microsoft.public.sqlserver.server)
  • Single-Threading / Performance issues
    ... In the database properties take off auto close and auto ... Other things you can look are server stuff. ... In the meanwhile get the book SQL Server 2000 Performance ... > From Query Analyser, I run my import proc - which first ...
    (microsoft.public.sqlserver.server)