Juarez Posted November 18, 2013 Share Posted November 18, 2013 Hi I have a shopping cart whereby the product details for each product are loaded from the MYSQL database into an array and echoed out onto the product page. I have been trying to change it so that the product has size options selected from a drop down and the selection then onchange will update the price accordingly. I assume the best way to do this is to have the two product options a small and a large with different prices stored in the database with different ID's. Then when the dropdown is changed to small for example the id for small is posted to the function which retrieves the product details. I think its a matter of adapting the function below to a condition where if the value posted is 's' then id = 1 else if value posted is 'L' then id = 2. in a variable, Though someone may have a better way of doing this. I have so far been unable to make this work. Any help would be appreciated. Here is the code to select the products from the database into an array. /** * finds products and lists them in DESC order * @return array */ function find_products() { db_connect(); $query = "SELECT * FROM products WHERE products.id = '1' "; $result = mysql_query($query); $result = db_result_to_array($result); return $result; } here is code which could post the drop down selection to the function above form name="SelectSize" action="DatabaSelectPage.php" method="post" ;> <p style = "font-family: Arial, Helvetica, sans-serif; font-size: 14px "> <select name="UpdatePrice" id="UpdatePrice" onchange="this.form.submit();" method="post"> <option value=""></option> <option value="S">S</option> <option value="L">L</option> </select> here is the code which echos out the product details from the array <?php foreach($products as $product): ?> <li> <a href="#"> <img src="../images/shop/<?php echo $product['myimage']; ?>" /> <h3><?php echo $product['title']; ?> -<br> £<?php echo number_format($product['price'], 2); ?></h3> <h3><?php echo $product['body']; ?></h3> <!--<h4><p><a href="index?view=add_to_cart&id=<?php echo $product['id']; ?>">add to cart</a></p></h4>--> </a> </li> <?php endforeach; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.