Re: Multiple MySQL Queries
| From: | sono-io at fannullone dot us | Date: | Tue, 28 Jul 2009 21:38:16 +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-295984@lists.php.net to get a copy of this message | ||
On Jul 28, 2009, at 12:48 PM, Jim Lucas wrote:
I just noticed something. This code places all items in a single <tr></tr> block. Each item needs to be separated, so using my example data above the html output would need to look like this: <tr><?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 UnitsItem# Description Price Item# Description Price 18247C4 -------- $85.89 A18247C4 ------- $76.32 18367C4 -------- $97.37 A18367C4 ------- $82.55
<td colspan="3">Starter Units</td>
<td colspan="3">Add-On Units</td>
</tr>
<tr>
<td>Item#</td>
<td>Description</td>
<td>Price</td>
<td>Item#</td>
<td>Description</td>
<td>Price</td>
</tr>
<tr>
<td>18247C4</td> <-- starter unit info
<td>--------</td> " "
<td>$85.89</td> " "
<td>A18247C4</td> <-- add-on unit info
<td>-------</td> " "
<td>$76.32</td> " "
</tr>
<tr>
<td>18367C4</td> <-- starter unit info
<td>--------</td> " "
<td>$97.37</td> " "
<td>A18367C4</td> <-- add-on unit info
<td>-------</td> " "
<td>$82.55</td> " "
</tr>
Thanks,
Frank