Hi everyone,
having a real headache over arrays at the moment. Had a search through the forums but can't find what im after so i'll begin here.
I'm in the process of setting up a shopping cart. I'm pretty much there with it all, however there is one thing which is giving me a really hard time.
My products can have attributes or options (e.g. i'm selling a t-shirt which can have different size and colour options) which are displayed in a drop down list.
My problem is, if I or a customer were to choose more than one option, e.g. a red, medium T-shirt, how would i store the two or more options in a session?
Here is my code for the drop down lists:
<select name="attribute['.$i.']" class="input" id="attribute['.$i.']">
and then some php to loop through the values.
The user would then select their desired option(s) and click on add to cart button.
Now were on add_cart.php, this is where i post the options and other details and then add it to the session.
My code for looping through the options is as follows:
$attribute = $_POST['attribute'];
$count = $_POST['count'];
$i = 0;
for($i=0;$i<$count;$i++){
$att_ref = $attribute[$i];
}
And my code to add info to the session.
// Add to the cart:
$_SESSION['cart'][$pid] = array ('quantity' => $qty, 'price' => $prod_price, 'description' => $desc, 'att_ref' => $att_ref);
My problem lies within the att_ref bit of the session / array.
the above code for looping through the options will pick out the correct attribute references, so if i chose option 1 and 4 $att_ref would return 14.
But when i try to add this to the session / array, it only ever adds 1 and not the 4.
So what i want to be able to do is store multiple values in the 'att_ref' => $att_ref bit and then be able to extract the values from the array and then display what options the customer chose in the view_cart.php page, which i can do, but it only ever pulls out the first option and not the 2nd and 3rd etc.
Any ideas?
Any help would be greatly appreciated!
Regards Dan.