Hi all,
I am facing a problem of arrays.The fact is that I am getting the array values but when i am running 2 arrays under a single for loop then I am only getting null values for the quantities….lets give you the code so that you can understand where the problem lies.
output of
echo “Key1: $key1; Value1: $value1<br />n”;
echo “Key2: $key2; Value2: $value2<br />n”;
is
Key1: 0; Value1: 1475
Key2: 0; Value2:
insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘1′,’1475′,”,’180.05′,’0’)
Key1: 1; Value1: 1476
Key2: 1; Value2:
insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘1′,’1476′,”,’196.74′,’0’)
Key1: ; Value1:
Key2: 2; Value2: 3
Key1: ; Value1:
Key2: 3; Value2: 5
As you see I am not getting the net_total and quantity
[code=php]//if the form is submitted
if(isset($_POST[‘image1_x’]))
{
$pid=$_POST[‘pid’];//product id
$quantity=$_POST[‘quantity’];
$item_price=$_POST[‘item_price’];
if($pid!=””)
{
for(
;
list($key1, $value1 ) = each( $pid ) ,
list($key2, $value2 ) = each( $quantity )
;
) {
echo “Key1: $key1; Value1: $value1<br />n”;
echo “Key2: $key2; Value2: $value2<br />n”;
foreach($item_price as $k=>$v)
{
list($v1,$v2)=explode(“#”,$v);//(price and pid)
if($value1!=””)
{
if($v2==$value1)//if pid==pid
{
$net_total=$value2*$v1;
$s_pro=”select pid from temp_cart where pid=’$value1′ and cart_id=’$cart_id'”;// TO SEE IF THE SELECTED PRODUCT IS ALREADY IN THE CART OR NOT
$q_pro=mysql_query($s_pro) or die(mysql_error());
$numrows=mysql_num_rows($q_pro); if($numrows==””)
{
//echo “insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘$cart_id’,’$value1′,’$value2′,’$v1′,’$net_total’)”;
$s_temp=”insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘$cart_id’,’$value1′,’$value2′,’$v1′,’$net_total’)”;
$q_temp=mysql_query($s_temp) or die(mysql_error());
header(“location:cart.php”);
}
else
{
$err=1;//one of the selected product is already in the cart
}
}
}
}
}
}
else
{
$emp=1;//no product has been selected
}
}
[code=html]//html form
<form name=”form1″ method=”post” action=””>
<table width=”95%” align=”center” cellpadding=”3″ class=”table”>
<tr>
<td width=”25%” class=”text” align=”center”>
<?=$icode;?>
</td>
<td width=”12%” class=”text” align=”center”>
<?=$design;?>
</td>
<td width=”9%” class=”text” align=”center”>
<input type=”text” name=”quantity[]” value=”” size=”7″>
</td>
<td width=”9%” class=”text” align=”center”>
<input type=”checkbox” name=”pid[]” value=”<?=$pid;?>”>
</td>
<td width=”10%” class=”text” align=”center”>
<?=$list;?>
</td>
<input type=”hidden” name=”item_price[]” value=”<?=$list.”#”.$pid;?>”>
</tr>
<tr>
<td colspan=”9″ class=”Subtitle” align=”center”>
<input type=”image” img src=”images/addtocart.gif” width=”85″ height=”17″ name=”image1″ value=”up”>
</td>
</tr>
</table>
</form>
Please suggest how to get the values from the quantity array
Thanks in advance for your co-operation.
Raj