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
https://forums.phpfreaks.com/topic/197656-php-while-loop/
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
https://forums.phpfreaks.com/topic/197656-php-while-loop/#findComment-1037324
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
https://forums.phpfreaks.com/topic/197656-php-while-loop/#findComment-1037404
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.