Re: More on removing item from cart

From: Date: Sun, 30 Jun 2002 23:39:17 +0000
Subject: Re: More on removing item from cart
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-104606@lists.php.net to get a copy of this message
Hi Vicki: I'm not going to cover everything in the email. BUT, the essence of the solution is right here. I made a little test script based on the values you said were in the cart array at the top of the page and the variables contained in the form... #! /usr/local/bin/php -q <?php # Simulate the $cart session variable: $cart[1] = 1; $cart[3] = 1; # Simulate the $checkbox array from the form: # $checkbox[1] = 'yes'; $checkbox[3] = 'yes'; # Run through each item in the cart: foreach($cart as $artID => $value) { if ( !isset($checkbox[$artID]) ) { unset($cart[$artID]); echo "<br />removed $artID from cart\n"; } else { echo "<br />kept $artID in cart\n"; } } ?> This behaves exactly as expected. Now, let's put my foreach loop from above (leave out all the rest of the stuff) in the place of your foreach loop (which is in the if($save) statement). Run it and things _should_ work right. --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

« previous php.general (#104606) next »