I'm working on shopping cart and I'm storing car_id
,price
and add on
items in session.I managed to store in the session but how do I retrieve them correctly as per id?
here's the code that stores inside the session:
$_SESSION['items'][$price]=array('total'=>$car_id,'add_on'=>$add_on);
This is how I retrieve them. I can show the id and price accodingly but not the addon ..Since one id can have multiple add on items and how do I store and retrieve accordingly in the same way?
<table>
<tr><th>price</th><th>Car id</th><th>Extras</th></tr>
<?php
foreach($_SESSION['items'] as $total=>$id)
{
?>
<tr>
<td width="100"><?php echo 'RM '.$total;?></td>
<?php
foreach($id as $ids)
{
?>
<td width="100"><?php echo $ids;?></td>
<td width="100"><?php if(isset($add_on)){ echo $add_on;} ?></td>
</tr>
<?php
}
}
?>
</table>
EDITED PART**
How to access array inside an array?
I got the above questioned answered. Now I', trying to access multiple value of addons that stored inside array.
which looks like this:
$_SESSION['items'][$price]=array('total'=>$car_id,array('add_on'=>$add_on,'dep'=>$dep));
Edited How do I pass the variable values array via url
if(isset($_POST['addon']))
{
if(isset($_POST['add_item']))
{
foreach($_POST['add_item'] as $item)
{
$item.'<br/>';
mysql_select_db($database);
$query_item="SELECT * FROM tbl_addons WHERE addOns_id='$item'";
$result_item=mysql_query($query_item);
while($row_item=mysql_fetch_array($result_item))
{
$dep=$row_item['Deposit'];
$ppd=$row_item['PricePerDay'];
echo $dep.'<br/>';
echo $ppd.'<br/>';
}
}