Re: session_name("CCLTrolley")
| From: | John Taylor-Johnston | Date: | Mon, 03 Oct 2005 18:51:38 +0000 |
| Subject: | Re: session_name("CCLTrolley") | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-223573@lists.php.net to get a copy of this message | ||
Is that over kill? No matter how I slam it, still referring to my Frankensteinian merge, "unset" does the job.
http://testesp.flsh.usherbrooke.ca/db/trolley.php
But then again, I will not require a quanity of items. The visitor will only want one copy of a bibliographic entry :-\ - I hope?!
You were checking to see if there was a greater than 1 quantity of post[RNum], right?
Thanks,
John
//Delete an entry:
if( isset( $_SESSION['TrolleyContents'][$_POST['RNum']] ) )
{
# $_SESSION['TrolleyContents'][$_POST['RNum']] -= 1;
# if( $_SESSION['TrolleyContents'][$_POST['RNum']] <= 0 )
# {
unset( $_SESSION['TrolleyContents'][$_POST['RNum']] );
# }
}
Robert Cummings wrote:
-- John Taylor-Johnston ----------------------------------------------------------------------------- "If it's not Open Source, it's Murphy's Law." ' ' ' Collège de Sherbrooke: ô¿ô http://www.collegesherbrooke.qc.ca/languesmodernes/ - 819-569-2064 °v° Bibliography of Comparative Studies in Canadian, Québec and Foreign Literatures /(_)\ Université de Sherbrooke ^ ^ http://compcanlit.ca/ T: 819.569.2064Thanks for your time and patience, JohnThe expression: $trolley[$item] -= $quantity; is a short form for the following: $trolley[$item] = $trolley[$item] - $quantity; Essentially we decrease the quantity of the given item by $quantity. if( $trolley[$item] < 1 ) { #Above we check if we subtracted more items than is physically possible unset( $trolley[$item] ); #If there are 0 or less items then there's no point having 0 of the item #in the trolley, so we unset the item from the array, which essentially #removes it completely. To view the difference at each step you can do #the following: <?php if( isset( $trolley[$item] ) ) { echo "Trolley before removing $quantity of $item<br />"; trolleyPrint(); $trolley[$item] -= $quantity; echo "Trolley after removing $quantity of $item<br />"; trolleyPrint(); if( $trolley[$item] < 1 ) {unset( $trolley[$item] );echo "Trolley after cleaning up empty entry for $item<br />"; trolleyPrint();} } ?> Cheers, Rob.