On Fri, 17 May 2002, Kelly Meeks wrote:
> Let's say I'm querying a table, and looping thru the results:
> 
> $connect=mysql_connect(host,user,pass);
> $thedb=mysql_select(database1);
> $thequery="select * from foo";
> $theresult=mysql_query($thequery) or die (mysql_error())
> while ($output=mysql_fetch_assoc($theresult)){
>    do stuff here..
> }
> 
> What if while I'm looping, I want to take the information I'm looping
> thru, and want to write it to completely different database, assuming
> that the same username and password info works for both databases?
> 
> Would you use multiple mysql_select_db statements, and then make refer.
> to the result of that select in your queries?

You don't need to switch back and forth unless you're actually sending 
queries to a particular database. Your result sets remain valid. Just make 
sure you don't overwrite them by using the same variables!

mysql_select_db($db1);
$result1 = mysql_query($query1);
 .. .. ..
mysql_select_db($db2);
$result2 = mysql_query($query2);
// $result1 and $result2 are both valid here

miguel


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

Reply via email to