Re: Array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ron Piggott wrote:
> The code I have so far for orders is below.  When a product hasn't been
> added it does what I want it to --- in giving the message "Your shopping
> cart is empty".  When a product is added, but then the user changes
> their mind I use the following lines of code to remove the selection:
> 
> UNSET($_SESSION['order'][$reference]['quantity']);
> UNSET($_SESSION['order'][$reference]);
> 
> It still leaves the variable   $_SESSION['order']   as an array, even if
> there are no selections in it.  The PHP command is_array is useless of
> weed out when there are no products.
> 
> What I would like to have happen is if the shopping cart is empty then
> the message "Your shopping cart is empty" be displayed 100% of the time.
> How do I achieve this?  What changes to my code below need to happen?
> 
> <?php
> if ( isset($_SESSION['order']) ) {
> #customer has begun creating order
> 
> foreach ($_SESSION['order'] AS $key => $value ) { 
> echo "Product: " . $key . " Quantity: " .
> $_SESSION['order'][$key]['quantity'] . "<br>\r\n";
> }
> 
> } else {
> #no products selected
> 
> echo "<ul class=\"lists\">\r\n";
> echo "<li>Your shopping cart is empty</li>\r\n";
> echo "</ul>\r\n";
> 
> }
> 

Or use unset, but unset the entire order:  unset($_SESSION['order'])

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux