I am having trouble sorting and displaying the data from two different databases on two different servers. They both contain and id field that have matching id's. They just happen to reside on different servers. I need to display all the information from both databases based on their id and display it in a table sorted on id. I've gotten to the point where I can get all the data I need from both tables, but I can't line them up in the table. The code below starts to put everything in line, but as soon as the loop hits a spot where the id's don't match up, it stops and starts outputting sorry in the else statement. I need it to pull everything from the first database and then pull from the second database and match all the id's in the first database. Any help is greatly appreciated.
$conn = dbfunction1();
mysql_select_db('db1');
$query = "SELECT * from table1";
$results = mysql_query($query);
$conn1 = dbfunction2();
mysql_select_db('db2');
$query1 = "SELECT * from table2;
";
$results1 = mysql_query($query1);
while (($row = mysql_fetch_array($results, MYSQL_ASSOC)) && ($row1 = mysql_fetch_array($results1, MYSQL_ASSOC))) {
$stid = $row['id'] ;
$cstid = $row1['building_id'];
if ($stid == $cstid){
echo "<div class='Row'>";
//results from query 2
echo "<div class='Cell'>"."<p>".$row['id']."</p>"."</div>";
echo "<div class='Cell'>"."<p>".$row['code']."</p>"."</div>";
echo "<div class='Cell'>"."<p>".$row['market']."</p>"."</div>";
echo "<div class='Cell'>"."<p>".$row['genre']."</p>"."</div>";
//results from query 1
echo "<div class='Cell'>"."<p>".$row1['building_id']."</p>"."</div>";
echo "<div class='Cell'>"."<p>".$row1['callsign']."</p>"."</div>";
echo "<div class='Cell'>"."<p>".$row1['session']."</p>"."</div>";
}
else {
echo "sorry!";
}
echo "</div>";
} //end while