Hi all,
I am developing a cart where the users can select multiple products with their respective quantities.I need to post 3 array values at a time.They are:
a)Product ID(pid)—-Array pid[]
b)Quantity (quantity)——Array quantity[]
c)Item price(item_price)——-Array item_price[]
[code=html]//html code within form
<input type=”text” name=”quantity[]” value=”” size=”7″ onchange=”if (/D/.test (this.value)) {alert (‘The quantity would be numeric’); this.value=”; this.focus()}”>
<input type=”checkbox” name=”pid[]” value=”<?=$pid;?>”>
<input type=”hidden” name=”item_price[]” value=”<?=$withdisc.”#”.$pid;?>”>//here I am joining the pid with the item price to match for which product what item price has been posted
[code=php]//after the form is being posted
if(isset($_POST[‘image1_x’]))
{
$pid=$_POST[‘pid’];
$quantity=$_POST[‘quantity’];
$item_price=$_POST[‘item_price’];
for(
;
list($key1, $value1 ) = each( $pid ) ,
list($key2, $value2 ) = each( $quantity )
list($key3, $value3 ) = each( $item_price)
;
)
{
//output of echo “Key1: $key1; Value: $value1<br />n”;
Key1: 0; Value: 1475
Key1: 1; Value: 1476
Key: ; Value:
Key: ; Value:
echo “Key1: $key1; Value: $value1<br />n”;
//output of echo “Key2: $key2; Value: $value2<br />n”;
Key2: 0; Value:
Key2: 1; Value:
Key2: 2; Value: 2
Key2: 3; Value: 3
echo “Key2: $key2; Value: $value2<br />n”;
//output of echo “Key3: $key3; Value: $value3<br />n”;
Key3: 0; Value: 152.71#1473
Key3: 1; Value: 174.31#1474
Key3: 2; Value: 180.05#1475
Key3: 3; Value: 196.74#1476
echo “Key3: $key3; Value: $value3<br />n”;
//how i can get the array elements which has value only…not the null values also i need to match the $item_price’s pid with the $pid and if it is matched then i have to run a insert query.Also the item_price needs to be multiply with the quantity.I have done something but in that case sometimes I am getting pid but not getting item_price or net_total or sometimes I am getting item_price and net_total but not getting pid.
“insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘$cart_id’,’$value1′,’$value2′,’$value3′,’$net_total’)”;
}
}
Please suggest me how can i get all the values of the insert query.
Raj