session cart remove

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • paolo

    session cart remove

    Hi

    I hope someone out there can help me.

    Im developing a sessionbased shoppingcart. When adding something in
    the cxart I do:
    session_start() ;
    $_SESSION["cart"][]=array("artnr" => $_GET["artnr"],
    "nr" => $_GET["nr"],
    "price" => $_GET["price"],
    "colors" => $_GET["colors"]
    );
    It works fine. BUT, when I want to remove one of these element in the
    cart: how should I proceed? I have read many post but dindnt find one
    suitable to my case.

    Thanks

    Paolo
  • Alvaro G Vicario

    #2
    Re: session cart remove

    *** paolo wrote/escribió (19 May 2004 04:28:10 -0700):[color=blue]
    > $_SESSION["cart"][]=array(...);
    > It works fine. BUT, when I want to remove one of these element in the
    > cart: how should I proceed? I have read many post but dindnt find one
    > suitable to my case.[/color]

    Maybe you could provide an index number for the array:

    $_SESSION['cart_top']++;
    $_SESSION["cart"][$_SESSION['cart_top']]=array(...);



    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --

    Comment

    • kingofkolt

      #3
      Re: session cart remove

      unset($_SESSION['cart'][$some_index]);

      to be able to get the correct value for $some_index, an idea is to have each
      item in your store be assigned an ID from the database that they're in
      (supposing you're using one). Then have $some_index be that ID, so that you
      can remove the right item from the cart when you want to.

      - JP

      "paolo" <paolooracle@ho tmail.com> wrote in message
      news:f9dc4b6.04 05190328.59c847 ad@posting.goog le.com...[color=blue]
      > Hi
      >
      > I hope someone out there can help me.
      >
      > Im developing a sessionbased shoppingcart. When adding something in
      > the cxart I do:
      > session_start() ;
      > $_SESSION["cart"][]=array("artnr" => $_GET["artnr"],
      > "nr" => $_GET["nr"],
      > "price" => $_GET["price"],
      > "colors" => $_GET["colors"]
      > );
      > It works fine. BUT, when I want to remove one of these element in the
      > cart: how should I proceed? I have read many post but dindnt find one
      > suitable to my case.
      >
      > Thanks
      >
      > Paolo[/color]


      Comment

      • paolooracle

        #4
        Re: session cart remove

        Yes, buit what do you do when you iterate?
        Say that $_SESSION['cart_top'] has become 5.
        Now you need to remove $_SESSION["cart"][3]
        Then you do unset($_SESSION["cart"][3]) I guess?
        What happens now? cart_top is still 5. So when you iterate
        $_SESSION["cart"][3] will fail, doesnt it?

        Paolo


        Comment

        • paolooracle

          #5
          Re: session cart remove

          IS not the same problem with your solution?
          I do like this now:
          $_SESSION["counter"]==null ? $_SESSION["counter"]=0 :
          $_SESSION["counter"]++;

          $_SESSION["cart"][$_SESSION["counter"]]=array(
          "artnr" => $_GET["nr"],
          "price" => $_GET["price"],
          "colors" => $_GET["colors"]
          );


          Comment

          • Alvaro G Vicario

            #6
            Re: session cart remove

            *** paolooracle wrote/escribió (Wed, 19 May 2004 15:04:07 GMT):[color=blue]
            > What happens now? cart_top is still 5. So when you iterate
            > $_SESSION["cart"][3] will fail, doesnt it?[/color]

            foreach($_SESSI ON["cart"] as $index){
            ...
            }

            --
            --
            -- Álvaro G. Vicario - Burgos, Spain
            --

            Comment

            Working...