phpanon Posted March 6, 2008 Share Posted March 6, 2008 Hi, My remove from basket is working exactly right. At the moment when [-] is clicked it removes the item from the basket even if the quantity is more than one. Ideally I would like to just decrease the quantity by one. <?php session_start(); foreach($_SESSION['basket'] as $key => $product) { if ($_SESSION['basket'][$key]['URN'] == $_GET['URN']) { unset($_SESSION['basket'][$key]); } } header("Location: StationaryMain.php?var=URN"); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/ Share on other sites More sharing options...
wildteen88 Posted March 6, 2008 Share Posted March 6, 2008 I presume $_SESSION['basket'][$key]['URN'] holds the quantity, if so something like the following should do it: <?php session_start(); foreach($_SESSION['basket'] as $key => $product) { if ($_SESSION['basket'][$key]['URN'] == $_GET['URN']) { // decrease quantity by one $_SESSION['basket'][$key]['URN']--; // unset quantity if new quantity is less than 1 if($_SESSION['basket'][$key]['URN'] < 1) { unset($_SESSION['basket'][$key]); } } } header("Location: StationaryMain.php?var=URN"); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485302 Share on other sites More sharing options...
phpanon Posted March 6, 2008 Author Share Posted March 6, 2008 Hi, I tried your suggestion... it doesn't seem to be working. It wont remove anything now?! Here it the code that calls that page too <a href="removefrombasket.php?URN=<?php echo $product['URN']?>">[-]</a> Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485322 Share on other sites More sharing options...
wildteen88 Posted March 6, 2008 Share Posted March 6, 2008 What does $_SESSION['basket'][$key]['URN'] and $product['URN'] hold? Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485324 Share on other sites More sharing options...
phpanon Posted March 6, 2008 Author Share Posted March 6, 2008 :-\ how do i check? lol Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485340 Share on other sites More sharing options...
wildteen88 Posted March 6, 2008 Share Posted March 6, 2008 Umm, you should now that, its your code... isn't? To find out: echo '<pre>' . print_r($_SESSION['basket'], true) . '</pre><br /><br />' . $product['URN']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485345 Share on other sites More sharing options...
phpanon Posted March 6, 2008 Author Share Posted March 6, 2008 this is what i got Array ( [0] => Array ( [uRN] => 2 [productName] => T2 Stapler [description] => Metal industrial Stapler. For use on all surfaces and walls. [price] => 12.99 [quantity] => 3 ) [1] => Array ( [uRN] => 5 [productName] => Year Planner [description] => A3 laminated Year Planner made from 100% recycled card. [price] => 19.99 [quantity] => 1 ) [2] => Array ( [uRN] => 1 [productName] => Ink 890 Cartridge [description] => High definition Ink cartridge for use with Laser Jet printers [price] => 24 [quantity] => 1 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485351 Share on other sites More sharing options...
phpanon Posted March 6, 2008 Author Share Posted March 6, 2008 ooh sorry, i miss understood your question!!?? URN is the ID of the product. Sorry Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485352 Share on other sites More sharing options...
wildteen88 Posted March 6, 2008 Share Posted March 6, 2008 I understand now what URN is, its the product identifier. I have modified my code. <?php session_start(); foreach($_SESSION['basket'] as $key => $product) { if ($_SESSION['basket'][$key]['URN'] == $_GET['URN']) { // decrease quantity by one $_SESSION['basket'][$key]['quantity']--; // unset quantity if new quantity is less than 1 if($_SESSION['basket'][$key]['quantity'] < 1) { unset($_SESSION['basket'][$key]); } } } header("Location: StationaryMain.php?var=URN"); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485355 Share on other sites More sharing options...
phpanon Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks for that. Yeah I realised what you meant by the question afterwards. Sorry about that Thank you for your time Quote Link to comment https://forums.phpfreaks.com/topic/94773-remove-from-basket/#findComment-485358 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.