Re: Multiple MySQL Queries
| From: | Jim Lucas | Date: | Tue, 28 Jul 2009 19:48:35 +0000 |
| Subject: | Re: Multiple MySQL Queries | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-295977@lists.php.net to get a copy of this message | ||
Please, click "Reply All" so the list may benefit from our talking.
Read below for further information.
sono-io@fannullone.us wrote:
> Jim,
>
>> if ( ( $results = mysql_query($SQL, $db) ) !== false ) {
>>
>> You want to have the inner portion processed then the comparison done.
>> Not the other way around.
>
> Of course, that makes sense. =:\
>
>> Sorry about the other typo's!
>
> No problem. That just helps to keep me on my toes! =;)
>
> If I may bother you for a little more help. How would I go about
> making the 2nd category display in a column in the same table as the 1st
> category, instead of a separate table, i.e.
>
> instead of displaying the products like this:
>
> itemid
> 14367C4
> 14487C4
> 14547C4
> 18247C4
> A14367C4
> A14487C4
> A14547C4
> A18247C4
> ...
>
> they would be displayed side by side in a single table like this:
>
> itemid itemid
> 14367C4 A14367C4
> 14487C4 A14487C4
> 14547C4 A14547C4
> 18247C4 A18247C4
> ...
>
> or am I asking too much now?
>
> Thanks again. I really do appreciate your help. I'm so much closer
> than I ever would have been on my own!
>
> Frank
>
> --------------------------
>
> FYI Here's the full code that works:
>
> <?php
> $item_list = "";
> $cats = array('01100-01200-01300-06403', '01100-02201-01300-06403');
>
> foreach ( $cats AS $cat ) {
> $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 ) {
> echo <<<HTML
> <table border="1">
> <tr>
> <th align="center">Item ID</th>
> <th align="center">Description<br />
> <font size="-1">(Click for more info)</font></th>
> <th align="center">Price Each</th>
> <th align="center">Purchase</th>
> </tr>
> HTML;
> while ( $item = mysql_fetch_assoc($result) ) {
> $price = money_format('%i', $item['unitprice']);
> echo <<<ROW
> <tr>
> <td>{$item['itemid']}</td>
> <td><a
> href="shop.cgi?c=detail.htm&itemid={$item['itemid']}">
> {$item['description']}</a></td>
> <td align="right">{$price}</td>
> <td><form action="shop.cgi" method="get">
> <input type="image" src="addtocart.png"
> name="addToCartButton" alt="Add To Cart" />
> <input type="hidden" name="itemid"
> value="{$item['itemid']}" />
> <input type="text" name="i_{$item['itemid']}"
> value="1"
> size="4" />
> <input type="hidden" name="c"
> value="viewcart.htm" />
> </form></td>
> </tr>
>
> ROW;
> }
> echo '</table>';
> } else {
> echo "No results for category #{$cat}!";
> }
> }
>
> ?>
<?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>';
?>