Search the Community
Showing results for tags 'multiple queries inside while'.
-
Hi All. I am having a problem displaying results of my page, maybe I think because I've poorly written the code. I have these tables: 1. customers (cust_id, name, address, TIN, price, timestamp) 2. purchases(po_id, cust_id, delivery_address, delivered, receivedby, paid, encoderid, agentid, timestamp) 3. po_content(table_id, po_id, prod_id, ordered, delivered, srp, timestamp) when generating a query, now that the database have a lot of content inside It's taking a while to display the result on the server and it shows "page cannot be displayed" while querying it from another computer via LAN. here's what I wrote: $rownum = 1; $a = "SELECT * FROM purchases ORDER BY timestamp ASC LIMIT $start $display"; $b = mysql_query($a); while ($c = mysql_fetch_array($) { $d = "SELECT * FROM po_content WHERE po_id='{$c['po_id']}'"; $e = mysql_query($d); while ($f = mysql_fetch_array($e)) { $amount = $amount + ($f['srp'] * $f['delivered']); } $total = $total + $amount; $g = "SELECT * FROM customers WHERE cust_id='{$c['cust_id']}'"; $h = mysql_query($g); $i = mysql_fetch_array($h); //bg stuff so it would be seen nicely if ($rownum % 2 == 0 ) { $bgcolor = '"bgcolor=#f3f3f3"'; } else { $bgcolor = '"bgcolor=#ffffff"'; } print ' <table width="100%" border="0" cellspacing="0" cellpadding="0" ' . $bgcolor . '> <tr> <td>' . $rownum . '. </td> <td>' . $c['po_id'] . '</td> <td>' . $i['name'] . '</td> <td>' . date('m d, Y', $c['timestamp']) . '</td> <td>$ ' . number_format($amount, 2) . '</td> <td>' . $agent . '</td> <td>' . $encoder . '</td> </tr> </table> '; $amount = 0; //reset the amount before looping again. } print '<td><div align="right">' . $number_format($total, 2) . '</div></td>'; There. $agent and $encoder has been called from an if(in_array) but still I think it adds up to the whole process. Now that the structure of the database has been like that. Would there be a damage control type thing that would optimize my queries? Many many thanks in advance!
- 4 replies
-
- php hangs?
- poor coding?
-
(and 1 more)
Tagged with: