Data from MySQL and Postgres Databases into Single HTML Table with PHP -


i need query mysql db, use part of results write query postgres db, display results both data sets in html table.

i have result of mysql query so

$orderid = array();  while ($row = mysql_fetch_array($qry_result)) {     $orderid[] = $row[order_id]; }  $orderlist =  implode(', ', $orderid ); 

ps: yes, know should using mysqli/pdo. old habits die hard.

$query2 = "select                              data1,                             data2,                             total                         order_summary os                          os.order_id in ($orderlist)                         limit 25"; 

so works, not fast i'd like, works. (suggestions on better way handle appreciated too!)

now, when try display i'm doing 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 table  $display_string .= "</tr>"; $display_string .= "</table>"; echo $display_string 

the issue either results mysql display in single row in html table or repeat on , over. intended result email paired order_id—once per row.

i feel i'm doing stupid here , easy fix. appreciated.

without seeing actual queries, longshot, should started.

first, fetch order_id , email mysql query, store results associative array.

while($row=mysql_fetch_array($result)) {     $orderid[$row['order_id']] = $row['email']; } 

since associative array, should order list with

$orderlist =  implode(', ', array_keys($orderid) ); 

if you're getting order id postgres, don't need query mysql again. instead, retrieve email doing

 $email = $orderid[$rowsrs['order_id']];  $display_string .= "<td>$email</td>"; 

mandatory reminder, use pdo!!! specially because when working 2 engines literally work half you're working now.

also, array keys must quoted. don't make poor php interpreter assume stuff.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -