I have problem with this simple shopping cart, I am going to pushing two different value from different table into arrays.
The value is product id & size id, its work to carry the value but the size appear not to be fix inside the cart.
2.php, This page for pushing value inside arrays.
3.php, This page for displaying result.
Question:
1)On the first submission, if I choose size 42, the result display 40 then increment on the next submission and so on.
Since I only have 3 size in my table, when the product submit four times it display nothing.
2)On the second submission and so on(with same product & size), the size_id is increment [1]40 > [2]41 > [3]42:
1.First submission : Fade 40 >> Name : Fade - Size : 40 - Qty : 1 -
2.Second submission: Fade 40 >> Name : Fade - Size : 41 - Qty : 2 -
Someone told me to use var_dump to see the array, but I don't know how to use it to fix my problem.
on : var_dump($_SESS ION['cart']);
I got this:
array(1) { [11]=> array(1) { [1]=> int(1) } }
array(1) { [11]=> array(1) { [1]=> int(2) } }
I hope anyone in this forum will help me, because I really need.
Thanks.
The value is product id & size id, its work to carry the value but the size appear not to be fix inside the cart.
2.php, This page for pushing value inside arrays.
Code:
switch($action){
case "add":
$_SESSION['cart'][$prod_id][$size_id]++;
break;
case "remove":
$_SESSION['cart'][$prod_id][$size_id]--;
break;
case "empty":
session_destroy();
break;
}
header("location:3.php");
?>
Code:
<?
foreach($_SESSION['cart'] as $item=>$sizes){
foreach($sizes as $size){
$prod = mysql_query("SELECT prod_name,size_id,size_number FROM a_prod,a_size WHERE prod_id='$item' AND size_id='$size'");
if(mysql_num_rows($prod) > 0){
list($prod_name, $size_id, $size_number) = mysql_fetch_row($prod);
echo "Name : ".$prod_name." - "."Size : ".$size_number." - "."Qty : ".$size.
"<a href=\"2.php?prod_id=$prod_id&size_id=$size_id&action=remove\"> - </a><br>";
}
}
}
?>
1)On the first submission, if I choose size 42, the result display 40 then increment on the next submission and so on.
Since I only have 3 size in my table, when the product submit four times it display nothing.
2)On the second submission and so on(with same product & size), the size_id is increment [1]40 > [2]41 > [3]42:
1.First submission : Fade 40 >> Name : Fade - Size : 40 - Qty : 1 -
2.Second submission: Fade 40 >> Name : Fade - Size : 41 - Qty : 2 -
Someone told me to use var_dump to see the array, but I don't know how to use it to fix my problem.
on : var_dump($_SESS ION['cart']);
I got this:
array(1) { [11]=> array(1) { [1]=> int(1) } }
array(1) { [11]=> array(1) { [1]=> int(2) } }
I hope anyone in this forum will help me, because I really need.
Thanks.
Comment