problem in shopping cart.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahia307
    New Member
    • Jun 2007
    • 32

    problem in shopping cart.

    i developed session based shopping cart. using this code.

    Code:
    	$_SESSION['cart'][]= array( 'prd_name' => $prd_name, 'unit_price' => $unit_price,
    	'qty' => $qty, 'id_prd' => $id_prd);
    and i use this code to display values placed in session.

    Code:
    foreach($_SESSION['cart'] as $key=>$value){
    echo $value['prd_name'];
    echo $value['qty']; 
    }
    Now my question is that. How can i update values placed in a session. i other words how can i update my shopping cart
    Last edited by Atli; Nov 26 '08, 07:21 AM. Reason: Removed excessive use of bold and underlined text.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    rahia307.

    Bold, italic and underlined text is meant to place emphasis on parts of your text, not the entire question. Making the whole thing bold, underlined AND italic only makes it harder to read and as such is not allowed.

    Please remember that when posting in the future!

    Thank you.
    Moderator

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      To update a session variable, you simple re-set it's value, just like you did when you first created it.

      The $_SESSION super-global works just like an array, and can be created, edited and unset just like any regular array.

      You can see an example of this in this article.

      Comment

      • rahia307
        New Member
        • Jun 2007
        • 32

        #4
        problem in session based shopping cart

        [QUOTE=rahia307; 3436578]i developed session based shopping cart. using this code.

        Code:
        	$_SESSION['cart'][]= array( 'prd_name' => $prd_name, 'unit_price' => $unit_price,
        	'qty' => $qty, 'id_prd' => $id_prd);
        and i use this code to display values placed in session.

        Code:
        foreach($_SESSION['cart'] as $key=>$value){
        echo $value['prd_name'];
        echo $value['qty']; 
        }
        Now my question is that. How can i update values placed in a session. i other words how can i update my shopping cart

        Comment

        • didoamylee
          New Member
          • Nov 2008
          • 16

          #5
          Well when you

          Code:
          $_SESSION['cart'][]= array( 'prd_name' => $prd_name, 'unit_price' => $unit_price,
          'qty' => $qty, 'id_prd' => $id_prd);
          you add to the $_SESSION['cart'] array another value. And it is stored like this:

          Code:
          $_SESSION['cart'][0] = your first product added
          $_SESSION['cart'][1] = your second product added
          // and so on
          so you might want to update your session like this ( knowing you $_SESSION['cart'] index. ) :

          Code:
          $_SESSION['cart'][0]['prd_name'] = 'another value';

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Do not double post your questions.

            Moderator.

            Comment

            Working...