Re: Transfer query result to another script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- Original Message ----- From: "Jochem Maas" <jochem@xxxxxxxxxxxxx>
To: "C.R.Vegelin" <cr.vegelin@xxxxxxxxx>
Cc: "David Giragosian" <dgiragosian@xxxxxxxxx>; "php-general" <php-general@xxxxxxxxxxxxx>
Sent: Friday, November 02, 2007 9:06 AM
Subject: Re:  Transfer query result to another script


C.R.Vegelin wrote:
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;

WRONG!!!

there is no reason to do a redirect, use an include to run code
relevant to the selected $output (and you'll have the result set available
for no extra charge).

and you can't stick resources (e.g. a resultset id) into session
and expect them to persist - the value may be there, but the resource
it pointed to is loooooong gone by the time the second script starts.

   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:  Transfer query result to another script


  On 11/1/07, C.R.Vegelin <cr.vegelin@xxxxxxxxx> 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


Hi Jochem,

The reason for a redirect is that Report.php has functionality such as
sorting on report columns, checkboxes to make graphs etc.

Suppose the following report columns:
  Country  06.Q1   06.Q2  06.Q3  06.Q4  07.Q1  07.Q2
1 Austria     1226     1211    1233    1328    1386    1362
2 Belgium    1004     1193    1008    9737    1102    1270
3 etc.

If I don't use a redirect but an include Report.php then Engine.php must be rerun:
- every time a user wants to sort on a columns, eg. Y06.Q1
- every time a user wants to make a graph with selected rows.

Right ? I did use an include but I'm changing it because of the reasons above.
I know it does have its price.

Regards, Cor

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux