1
我有會議存儲物品信息數組,每個物品都有我想要的數量,當用戶選擇相同的物品時只需增加數量而不是再次添加。 當我增加一個項目的數量沒關係,但是當我增加許多項目的數量只有它可以爲第一個,其他正在增加,但在同一時間他們複製數量1購物車會話重複數量
例如我選擇x 3次和y 2
X3 2 Y 1Y 1Y
//if it's the first item
if (!isset ($_SESSION['Cart']))
{
$CartItem = array ($I_ID,$I_Name,$I_Price,$I_img,$quantity);
$_SESSION['Cart'][] = $CartItem;
header('Location:salad.php');
}
//if the session contains items check if the item already exist
else if (isset ($_SESSION['Cart']))
{
foreach($_SESSION['Cart'] as $y)
{
if($y[1] == $I_Name)
{
$_SESSION['Cart'][$i][4]++; //increment quantity
header('Location:salad.php');
break;
}
else{
$CartItem = array($I_ID,$I_Name,$I_Price,$I_img,$quantity);
$_SESSION['Cart'][] = $CartItem;
header('Location:salad.php');
}
$i++;
}
}
>
這是工作(f)@mouradk – huda 2014-12-19 11:42:02