1
好的,我遇到了這個問題。我試圖將產品添加到購物車的產品作爲選項顏色等,但我似乎無法做到正確。如果我點擊「添加到購物車」,它會每次都會計數,但是如果我改變顏色,那麼它就會出錯。幫助,男生和女生!一直在這方面工作了一段時間。購物車陣列和會話
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