آره . تو Session ذخیره میشه . این کدشه قرارگیری کالاها در session:
if(isset($_GET['do']) && $_GET['do']=="addcart")
{
$id = intval($_GET['id']);
if(isset($_SESSION['cart'][$id]))
{
$_SESSION['cart'][$id]['qty']++;
}else
{
$res=@mysql_query("SELECT * FROM `products` WHERE `id`='{$id}'");
if(mysql_num_rows($res)!=0)
{
$row=mysql_fetch_assoc($res);
if($row['price']>0)
{
$_SESSION['cart'][$row['id']]=array(
'qty' => 1 ,
'price' => $row['price']
);
}
}
}
این هم کد نمایش جدول :
<table class="ordertable">
<tr>
<th> نام </th>
<th> تعداد </th>
<th> قيمت </th>
<th> کل </th>
</tr>
<?php
$sql="SELECT * FROM `products` WHERE `id` IN(";
foreach($_SESSION['cart'] as $id => $value)
{
$sql.=$id.",";
}
$sql=substr($sql,0,-1).") ORDER BY `name` ASC";
$query=mysql_query($sql);
if($query)
{
$totalprice=0;
$tr=1;
while($row_r=mysql_fetch_assoc($query))
{
$subprice=$_SESSION['cart'][$row_r['id']]['qty']*$row_r['price'];
$totalprice+=$subprice;
if($tr%2==0)
echo '<tr style="background:#f8f8fc;">';
else
echo '<tr>';
?>
<td width="45%" style="text-align:right"><?php echo $row_r['name']; ?></td>
<td width="10%"><input type="text" maxlength="4" name="qty[<?php echo $row_r['id']; ?>]" class="ordervalue" value="<?php echo $_SESSION['cart'][$row_r['id']]['qty']; ?>"/></td>
<td width="25%"><?php echo $row_r['price']; ?></td>
<td width="25%"><?php echo $_SESSION['cart'][$row_r['id']]['qty']*$row_r['price']; ?></td>
</tr>
<?php
$tr++;
} // end of while fetch
} // end of if query
?>
</table>