I'm trying to work with data drawn from 2 separate databases. So there have to be two separate queries.
I'm not having any problems getting things to work, but I'm not sure I'm coding it the most efficient way.
What I'm doing is getting the main data from db1, then getting some additional data from db2 based on results of 1st query, then using the combined data to get the material for web display.
I won't display all the detailed coding, but this will give the general idea of what I'm doing:
$sql1 = "SELECT * FROM db1_table";
$res1 = mysql_query($sql1);
while ($row1 = mysql_fetch_array($res1) {
..blah blah getting an array of one field
}
//then I take that array and use it to get data from the 2nd db
$sql2 = "SELECT some_field FROM db2_table WHERE id IN (array from first while loop)";
$res2 = mysql_query($sql2);
while ($row2 = mysql_fetch_array($res2) {
blah blah creating array of 'some_field' to be used later
}
//now that I have that secondary data, I have to go back to
// the first result and run another while loop
mysql_data_seek($res1, 0);
while ($row3 = mysql_fetch_array($res1) {
blah blah create output based on the combined data
}
I'm just trying to figure out if 3 loops are really necessary. As for the second query, the table is several million rows. So I can't simply run a query without first having the results of $query1.