Re: Multiple MySQL Queries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 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); //sanitizes the data to prevent SQL injection
   $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 = "$" . 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>';
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux