Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi New here so Hello to everyone,
I basically signed up to ask for help. I have a shopping cart system and im using S_SESSION variables to hold what has been put into the shopping cart. It's going great and can put as many products has I like in it. The problem is when I try to remove the items it going wrong. i have a quality system and that working, as well as moving the last and first prouct. The problem is when I try to delete product number 5 from 10. As anyone got code to help me do this. This is what I have so far:Code: Select all
<?php
/*
manu=".$manufacturer
product=".$product
size=".$size
*/
$manu = $_GET['manu'];
$product = $_GET['product'];
$size = $_GET['size'];
//print_r($_SESSION);
$numincart = $_SESSION['numincart'];
for($i=0;$i<$numincart;$i++)
{
if (($manu == $_SESSION[$sid][$i]['manufacturer']) && ($product == $_SESSION[$sid][$i]['product']) && ($size == $_SESSION[$sid][$i]['size']))
{
if($_SESSION[$sid][$i]['quantity'] > 1)
{
echo("wrong place");
$quantity = $_SESSION[$sid][$i]['quantity'];
$quantity--;
$_SESSION[$sid][$i]['quantity'] = $quantity;
}
else
{
// code here to take out product from array
echo("wrong place 2");
// unset($_SESSION[$sid][$i]);
$array_pop = array_pop($_SESSION[$sid]);
$_SESSION[$sid][$i]['id'] = $array_pop['id'];
$_SESSION[$sid][$i]['product'] = $array_pop['product'];
$_SESSION[$sid][$i]['stock_code'] = $array_pop['stock_code'];
$_SESSION[$sid][$i]['price'] = $array_pop['price'];
$_SESSION[$sid][$i]['manufacturer'] = $array_pop['manufacturer'];
$_SESSION[$sid][$i]['quantity'] = $array_pop['quantity'];
$_SESSION[$sid][$i]['size'] = $array_pop['size'];
$numincart--;
$_SESSION['numincart'] = $numincart;
}
}
/* else
{
echo("here");
$array_pop = array_pop($_SESSION[$sid]);
print_r($array_pop);
$numincart--;
$_SESSION['numincart'] = $numincart;
}
*/
}
?>As you can see im holding the products in a array. normally using C\C++ I would just use a dynamic link list and redirect the pointer varible and malloc the removed product.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]