jay_bo Posted April 5, 2010 Share Posted April 5, 2010 I have to while loops inside one while loop wich seems to stop the first loop from running. if ($cat!="") { $result=mysql_query("SELECT * FROM products WHERE cat_id=$cat"); while($row=mysql_fetch_array($result)){ echo '<br />'; echo '<div id="item_container">'; echo '<div id="item_picture"><a href="'.$row["picture_large"].'" class="thickbox" rel="album" ><img src="'.$row["picture"].'" border="0" alt="'.$row["image_alt"].'"></a></div>'; echo '<div id="item_title"><h2>'.$row["name"].'</h2></div>'; echo '<div id="item_text"><p>'.substr($row["description"], 0, 100).'</p><br /><br />'; echo '<select name="dropdown">'; $type=$row["type"]; $sql="SELECT * FROM products WHERE type=$type"; $result =mysql_query($sql); while ($row=mysql_fetch_assoc($result)){ echo'<option value =<"'.$row["serial"].'" >'.$row["price"].'</option>'; } echo '</select>'; echo '<br /><br/>'; echo '<input type="button" value="Add to Cart" onclick="addtocart('.$row["serial"].')"/></span>'; echo '</div>'; echo '<br />'; echo '<br />'; echo '</div>'; } } Quote Link to comment Share on other sites More sharing options...
ignace Posted April 5, 2010 Share Posted April 5, 2010 Rename your $result and $row in your inner-while loop Quote Link to comment Share on other sites More sharing options...
jay_bo Posted April 5, 2010 Author Share Posted April 5, 2010 Thanks, i thought i had renamed that before big help! When i press the button in the code above it goes to this code.... <script language="javascript"> function addtocart(pid){ document.form1.productid.value=pid; document.form1.command.value='add'; document.form1.submit(); } </script> Then if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){ $pid=$_REQUEST['productid']; addtocart($pid,1); header("location:shoppingcart.php"); exit(); } ** Which are all in the page.... My question is how would i be able to get the value from the dropdown box into the php code just above? Thanks Quote Link to comment Share on other sites More sharing options...
ignace Posted April 5, 2010 Share Posted April 5, 2010 By using $_REQUEST['dropdown'] as <select name="dropdown"> Quote Link to comment Share on other sites More sharing options...
jay_bo Posted April 5, 2010 Author Share Posted April 5, 2010 okay so $_REQUEST['dropdown'] seems to get the product id from the dop down list...However it also adds the last product id aswel so that i get two product ids. Do you get what i mean? Quote Link to comment Share on other sites More sharing options...
jay_bo Posted April 5, 2010 Author Share Posted April 5, 2010 Ive just realised that it basicallys add my first product and what ever i have selected in the drop down list and then it also adds the product underneath and its first selected item... how can i stop it from adding the second product? For example, my url... http://localhost%20Site/orderonline.php?command=&productid=98&command=&productid=99 first product - command=&productid=98 second product - command=&productid=99 I need it just to contain the first product like ... http://localhost%20Site/orderonline.php?command=&productid=98 I think it is something to do with the while loop 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.