Re: Switching dbs in midstream
| From: | Cam Dunstan | Date: | Sun, 27 Oct 2002 23:12:06 +0000 |
| Subject: | Re: Switching dbs in midstream | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-16582@lists.php.net to get a copy of this message | ||
John,
Theres nothing to stop you doing aother query within then loop of the first
provided that you don`t send the result to the same result handle or the
same row array - in other words .....
$result =mysql_query($sqlstatement);
while ($row = mysql_fetch_array($result)) {
// do stuff
mysql_select_db($anotherdb);
$resultnew = mysql_query($sqlstatementnew);
$rownew =mysql_fetcharray($sqlstatementnew);
//do stuff with $rownew
//mysql_select_db($formerdb); don`t need this - just keep using
//$result and $row for continuing work with first query
// or add the two arrays - depending on what you are doing
}
Think of $result (which is just an integer) as a pointer or a handle to a
two dimensional array of real data.
If you use the original $result and $row for the inner query, the inner or
second query will "overwrite" the first entirely.
Hope I have understood what you are trying to do here. There is also a
possibility that what you want can also be achieved with one "joined" query
statement incorporating a GROUP BY clause.
Cheers CD
----- Original Message -----
From: "John Meyer" <johnmeyer_1978@yahoo.com>
To: <php-windows@lists.php.net>
Sent: Monday, October 28, 2002 3:59 AM
Subject: [PHP-WIN] Switching dbs in midstream
> Hi,
> I have a situation where I may have to switch the database while I am
> looping a resultset. If I do a mysql_select_db within the middle of that,
> will that change the initial resultset, e.g
>
>
> while ($row = mysql_fetch_array($result)) {
>
> mysql_select_db($anotherdb);
> //do stuff
> mysql_select_db($formerdb);
> }
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>