I need to query a MySQL DB, use part of the results to write a query for a Postgres DB, then display results from both data sets in an HTML table.
I have a the result of the MySQL query like so
$orderid = array();
while ($row = mysql_fetch_array($qry_result)) {
$orderid[] = $row[order_id];
}
$orderlist = implode(', ', $orderid );
PS: Yes, I know that I should be using mysqli/PDO. Old habits die hard.
$query2 = "SELECT
data1,
data2,
total
FROM order_summary os
WHERE os.order_id IN ($orderlist)
LIMIT 25";
So that works, not as fast as I'd like, but it works. (Suggestions on a better way to handle that are appreciated too!)
Now, when I try to get this to display I'm doing something like this:
$result2 = pg_query($query2) or die('Query failed: ' . pg_last_error());
while ($rowrs = pg_fetch_array($result2, null, PGSQL_ASSOC)) {
$display_string .= "<tr class='text-center'>";
$display_string .= "<td>$rowrs[data1]</td>";
$display_string .= "<td>$rowrs[data2]</td>";
$display_string .= "<td>\$$rowrs[total]</td>";
$qry_result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<td>$row[email]</td>";}
}
//magical other things unrelated to the table
$display_string .= "</tr>";
$display_string .= "</table>";
echo $display_string
The issue is that either the results from MySQL display in a single row in the HTML table or repeat over and over. The intended result would be the email paired with the order_id—once per row.
I feel like I'm doing something stupid here and this is an easy fix. Any help is greatly appreciated.