PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
if I remove: $_SESSION['products'] = array();
the code lends me this to the same scenario above...adding two different items to the cart
prod idProduct_14 => 14prod idProduct_15 => 15
Last edited by fitchic77 on Sat Oct 16, 2010 11:29 am, edited 1 time in total.
<?php
// Start the session, remembering that
// we do this for every page in the session scope
$session_start();
// Grab the id from the URI if there is one
// If there isn't one, default to 0
$id = ( isset($_GET['id']) ) ? $_GET['id'] : 0;
// Now, since the id is a single value,
// we do not need to array the product ID session var
// But we can in case later on there is another
// Selected id
$_SESSION['products'] = array();
$_SESSION['products']['product_' . $id] = $id;
?>
So, if a user clicked three links with an id querystring var, and on page one clicked on page.php?id=45, then the user clicked on page.php?id=26 then page.php?id=922, your session product array would look like this...
Yes. It should store all 3, but as soon as I uncomment out : $_SESSION['products'] = array(); it doesn't store more than one "idProduct"... I SWEAR....
Isn't it by default an ARRAY?
Could this be a php.ini setting difference?
Last edited by fitchic77 on Sat Oct 16, 2010 11:28 am, edited 1 time in total.
$_SESSION is an array, so I suppose technically you don't have to declare the $_SESSION['products'] an array because it will automatically fit into that category .Although good coding practises say you should declare your variables. I cannot see how telling your script that a particular var is an array is going to make it a string. That doesn't make sense to me.
It isn't a string...it is just storing them all...the display I entered was a little decieving...sorry about that. It just shows all values in the loop idproduct_1 ==>1. I should have put a <br> in the loop.
Sorry about that...thanks again for your help...You saved my project!
Now I can successfully build my cart, remove items and update items...
Last edited by fitchic77 on Sat Oct 16, 2010 11:28 am, edited 1 time in total.