Re: Multiple MySQL Queries
| From: | sono-io at fannullone dot us | Date: | Tue, 04 Aug 2009 15:40:58 +0000 |
| Subject: | Re: Multiple MySQL Queries | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296274@lists.php.net to get a copy of this message | ||
Is what I'm looking to do not possible in PHP? I've come close with a JavaScript version, but I'd rather not rely on everyone having JS turned on. Or am I stuck having to use JS?
Thanks again,
Frank
I'd like to revisit this one last time. Below is the revised code I'm using, but I don't like having individual 'Add To Cart' buttons for each item. I've tried to find a way to have only one that resides outside the nested tables for all items, but without luck. It would need to send every item that has a quantity to the cart, but only those items. The URL that would be passed needs to look like this: /shop.cgi?c=viewcart.htm&itemid=P74S&i_P74S=80&S2448S&i_S2448S=100&AC&i_AC=26 (The above URL is sending 3 items and their quantities to the cart; 80 - P74S, 100 - S2448S and 26 - AC.) Thanks again for all your help. I'm learning a lot on this list - albeit slowly! ;) Regards, Frank ------------------------ <?php $cats = array('02121-19222-13349-11451' => 'Stationary Posts','04103-99222-48340-11422' => 'Solid Galvanized Shelves'); echo '<table border="1"><tr>'; foreach ( $cats AS $cat => $title) { echo <<<START <td valign="top"> <table border="1"><tr><th align="center" colspan="4">{$title}</th></tr> <tr> <td class="text-header" align="center">Item#</td> <td class="text-header" align="center">Description<br /><span class="text-small">(Click for more info)</span></td><td class="text-header" align="center">Price</td> <td class="text-header" align="center">Qty</td> </tr>START; $cat = mysql_real_escape_string($cat, $db); $SQL = "SELECT itemid,description,unitpriceFROM catalog WHERE categories='$cat' ORDER BY itemid";if ( ($result = mysql_query($SQL, $db)) !== false ) {while ( $item = mysql_fetch_assoc($result) ) { $price = "$" . number_format($item['unitprice'],2); echo <<<ROW<tr><td class="text-med">{$item['itemid']}</td> <td class="text-med"><a href="/shop.cgi?c=detail.htm&itemid={$item['itemid']}">{$item['description']}</a></td> <td class="text-med" align="right">{$price}</td><td class="text-med"><form action="/shop.cgi" method="get"> <input type="hidden" name="itemid" value="{$item['itemid']}" /> <input type="text" name="i_{$item['itemid']}" value="" size="4" /> <input type="hidden" name="c" value="viewcart.htm" /> <input type="image" src="/graphics/addtocart.png" name="addToCartButton" alt="Add To Cart" /></form></td></tr> ROW;}} else {echo "No results for category #{$cat}!";} echo '</table></td>'; } echo '</tr></table>'; ?>