I have problem with this 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>";
}
}
}
}
?>
For the first submission it appear to be normal. 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 -
Since I only have 3 size in my table, when the product submit four times it display nothing.
It also happen for same product but different size, keep getting the first size in table rather chosen one.
It display these:
Name : Sonar - Size : 40 - Qty : 1 -
Name : Sonar - Size : 40 - Qty : 1 -
Rather than this:
Name : Sonar - Size : 40 - Qty : 1 -
Name : Sonar - Size : 42 - Qty : 1 -
I try to put if around the case "add" on 2.php, with condition "if the size exist it will only increment the product", but it did not work.
This is page right before that page above, which increment the value.
<?
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");
?>
Im stuck, I need help thanks.