好的,我有这个问题。我正在尝试将产品添加到购物车作为选项颜色等,但我似乎无法正确处理。如果我只是点击“添加到购物车”,它每次都会计数,但如果我改变颜色,它就会开始出错。帮助,男孩和女孩!已经为此工作了一段时间。
if(isset($_POST['submit'])){
$id = $_POST['id'];
$sleeve = $_POST['sleeve'];
$colour = $_POST['colour'];
$size = $_POST['size'];
$action = $_POST['action'];
$quantity = 1;
}
if(!isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id] = array($id, $colour, $size, $quantity);
}
else{
if(isset($_SESSION['cart'][$id])){ // if the session as already been set then..
while(list($key, $value) = each($_SESSION['cart'])){ // while loop to chech to content of the session..
if($value[0] == $id && $value[1] == $colour && $value[2] == $size){ // checking to see if the session content is the same..
$quantity = $value[3] +=1;
$_SESSION['cart'][$id] = array($id, $colour, $size, $quantity); // if it is the same then add this..
}// if is ==
else{
$quantity +=1;
$_SESSION['cart'][$id][] = array($id, $colour, $size, $quantity); // is session is not the same do this..
}//else if it is not ==
}// while
}// if isset
}// else isset session