gerkintrigg Posted July 24, 2006 Share Posted July 24, 2006 Hi everyone.Ive been trying to ad items to an array for a shop. I can define them by hard coding it, but for my dynamic shop, that's a bit pointless...Here's the code that DOES add to the array:[code]<?php$_SESSION['flop']['2'] = 'whatever';$_SESSION['flop']['1'] = 'whatever 2'; foreach($_SESSION['flop'] as $item_id => $quantity){$item_details=mysql_fetch_array(mysql_query("select * from items where item_id='". $item_id."'")); echo "Item = ".$item_details['item_title']." , Quantity: $quantity <br>";}?>[/code]This echoes two lines with the contents of each bit of data.The problem is using an auto script to pick up user input and add that to the same array. Here's the code I have:[code]<?phpinclude '../includes/db.php';if (! isset($_SESSION['flop'])){$_SESSION['flop']=array();}$new=$_REQUEST['new'];if(isset($_SESSION['flop'][$new])){ $_SESSION['flop'][$new]=$_SESSION['flop'][$new]+1; } else $_SESSION['flop'][$new] = 1;if (isset($_SESSION['flop'])){ foreach($_SESSION['flop'] as $item_id => $quantity){$item_details=mysql_fetch_array(mysql_query("select * from items where item_id='". $item_id."'")); echo "Item = ".$item_details['item_title']." , Quantity: $quantity <br>";}}else{ echo "No items in your shopping cart";}?>[/code]There are no error messages, but it only ever shows one of the variables rather than all of them. Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted July 24, 2006 Author Share Posted July 24, 2006 Sorry, forgot to add session_start(); to the top of the script...Silly me!! Quote Link to comment 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.