Re: Transfer query result to another script
| From: | C.R.Vegelin | Date: | Fri, 02 Nov 2007 08:52:54 +0000 |
| Subject: | Re: Transfer query result to another script | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263958@lists.php.net to get a copy of this message | ||
Hello David, Jim,
Thanks for your response.
Yes, I do have session_start() at the top of Report.php.
The reason for having the query on a different page than the result
is that the result may be sent to various output types / scripts.
I will change my code as follows:
Engine.php
-------------
$result = mysqli_query($connect, $myquery);
if (!$result) error ...
if (mysqli_num_rows($result) == 0) error ...
// fill $_SESSION['results'] with query result
switch ($output)
{
case "HTML": header("Location: Report.php"); break;
case "CSV": ...
case "XML": ...
case "PDF": ...
}
Thanks again for your advice.
Regards, Cor
----- Original Message -----
From: David Giragosian
To: C.R.Vegelin ; php-general
Sent: Thursday, November 01, 2007 5:23 PM
Subject: Re: [PHP] Transfer query result to another script
On 11/1/07, C.R.Vegelin <cr.vegelin@hetnet.nl> wrote:
Hi All,
Q: Is it possible to transfer a query result to another script ?
For example with (fragments of) the following 2 scripts:
Engine.php
----------------
$result = mysqli_query($connect, $myquery);
if (!$result) error ...
if (mysqli_num_rows($result) == 0) error ...
$_SESSION['result'] = $result;
header("Location: Report.php");
Report.php
----------------
$result = $_SESSION['result'];
while ($row = mysqli_fetch_array($result)) ...
This last line gives "Couldn't fetch mysqli_result".
Is this because the result set is local to Engine.php ?
TIA, Cor
Cor,
Do you have session_start() at the top of Report.php?
The manual shows an example of passing a php created class object using a session variable, with
the caveat of needing to include the class definition on each page.
It may be different for a mysql result object though.
Why do you need the query on a different page than the result?
David