Jump to content

PHP while loop


jay_bo

Recommended Posts

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>';
}
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.