Re: Multiple MySQL Queries
| From: | sono-io at fannullone dot us | Date: | Tue, 28 Jul 2009 20:54:26 +0000 |
| Subject: | Re: Multiple MySQL Queries | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-295983@lists.php.net to get a copy of this message | ||
On Jul 28, 2009, at 12:48 PM, Jim Lucas wrote:
<?php $item_list = ""; $cats = array('01100-01200-01300-06403', '01100-02201-01300-06403'); echo '<table border="1">'; echo '<tr>'; foreach ( $cats AS $cat ) { echo '<th>'.htmlspecialchars($cat).'</th>'; } echo '</tr><tr>'; foreach ( $cats AS $cat ) { echo '<td>'; $cat = mysql_real_escape_string($cat, $db); $SQL = "SELECT itemid,description,unitprice FROM catalog WHERE categories='$cat' ORDER BY itemid"; if ( ($result = mysql_query($SQL, $db)) !== false ) { while ( $item = mysql_fetch_assoc($result) ) { $price = money_format('%i', $item['unitprice']); echo <<<ROW <a href="shop.cgi?c=detail.htm&itemid={$item['itemid']}" {$item['description']}</a> ROW; } } else { echo "No results for category #{$cat}!"; } echo '</td>'; } echo '</tr></table>'; ?>We're getting close! This now displays everything in 2 columns. Ultimately, what I need is a display like this: Starter Units Add-On Units
Item# Description Price Item# Description Price 18247C4 -------- $85.89 A18247C4 ------- $76.32 18367C4 -------- $97.37 A18367C4 ------- $82.55I got the headers to work with this code: ... foreach ( $cats AS $cat ) { echo '<th align="center">Item ID</th>'; echo '<th align="center">Description<br />'; echo '<font size="-1">(Click for more info)</font></th>'; echo '<th align="center">Price Each</th>'; echo '<th align="center">Purchase</th>'; } echo '</tr><tr>'; ... (I don't need to show the category #'s in the header fields) but I can't get the rest of the data to flow like I want it. Thanks, Frank