hi,
how could i add a quantity feature to this shopping cart. any tips or places too look?
add the item...
<? session_start();
if ( !isset( $_SESSION["cart"] ) ) {
$_SESSION["cart"] = array();
}
$id = $_POST["id"];
$_SESSION["cart"][$id] = $id;
header("location:index.php");
?>
to view the items (some css and html cut out) - can i use the explode function and how?
<?php
session_start();
$session = $_SESSION['cart'];
$count = count($session);
if($count==0){
header("location:cart_empty.php");
}
else {
?>
<body>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="header">
<tr>
<td valign="top"><iframe frameborder="0" scrolling="no" width="100%" height="100px" src="../IFRAME_header.php"></iframe></td>
</tr>
<tr>
<td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="190" rowspan="2"><img src="../images/navtopcorner.bmp" alt="" width="156" height="40" /><img src="../images/navtop.png" alt="" width="34" height="40" /></td>
<td class="mainnavbg"> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" bgcolor="#EFEFEF" class="menuleft"><iframe scrolling="no" src="../menu.php" class="iframemenu" frameborder="0"></iframe></td>
<td width="100%" align="center" valign="top"><table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" style="background-image:url(../images/line_1x10.png); background-repeat:repeat-x; width:100%; height:1px; padding-top:10px"></td>
</tr>
</table>
<table width="95%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td align="left" valign="middle"><span class="style17">Shopping Cart - <? $session = $_SESSION['cart'];
echo count($session); ?> Item(s) </span></td>
</tr>
</table>
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" style="background-image:url(../images/line_1x10.png); background-repeat:repeat-x; width:100%; height:1px"></td>
</tr>
</table>
<table width="95%" border="0" cellspacing="3" cellpadding="0" style="padding-top:5px">
<tr>
<td align="left" valign="top" class="style26"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<?php
foreach($_SESSION['cart'] as $value)
{
?>
<table width="100%" border="0" cellpadding="2" cellspacing="1"><tr><td><?php
$con = mysql_connect("**********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("******", $con);
$result = mysql_query("SELECT * FROM items WHERE id='$value'");
$info = mysql_fetch_array( $result);
$count=mysql_num_rows($result);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td align="left" valign="middle" nowrap="NOWRAP"><form id="id" name="id" method="post" action="/cart/remove_item.php">
<input type="image" src="/images/x2.gif" alt="Remove This Item">
<input name="id" type="hidden" id="id" value="<?php echo $info['id']; ?>" />
</form> <a href="/remove_item.php"></a></td>
<td align="left" valign="bottom" nowrap="NOWRAP"> </td>
<td width="60" height="60" align="center" valign="middle" nowrap="NOWRAP"><img src="<? echo $info['image']; ?>" alt="<?
echo "#";
echo $info['code'];
echo " - ";
echo $info['name'];
?>" class="cartimage"/></td>
<td width="100" align="left" valign="middle" nowrap="NOWRAP"><? echo $info['code']; ?></td>
<td width="90%" align="left" valign="middle"><strong><? echo $info['name']; ?></strong> </td>
<td align="right" valign="middle"><form id="form1" name="form1" method="post" action="" style="display:inline">
</form>
</td>
<td align="left" valign="middle" nowrap="nowrap">£<? echo $info['price']; ?></td>
</tr>
</table></td>
</tr></table>
<?
$sub[]=$info['price'];
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" style="background-image:url(../images/line_1x10.png); background-repeat:repeat-x; width:100%; height:1px"></td>
</tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" align="right" cellpadding="3" cellspacing="0">
<tr>
<td width="100%" align="right" valign="middle">Subtotal : </td>
<td align="right" valign="middle"> </td>
<td align="right" valign="middle">£<?
$subtotal = array_sum($sub);
echo number_format($subtotal, 2, '.', ',');
?></td>
</tr>
<tr>
<td width="100%" align="right" valign="middle">P + P : </td>
<td align="right" valign="middle"> </td>
<td align="right" valign="middle">£2.00</td>
</tr>
<tr>
<td colspan="3" align="right" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" style="background-image:url(../images/line_1x10.png); background-repeat:repeat-x; width:100%; height:1px"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="100%" align="right" valign="middle"><span class="style27">Total:</span></td>
<td align="right" valign="middle"> </td>
<td align="right" valign="middle" nowrap="nowrap"><span class="style27">£
<?php
$postage = 2.00;
$item_total = array_sum($sub);
$final = $item_total + $postage;
$total_price = number_format($final, 2, '.', ',');
echo $total_price;
$_SESSION["total"]=$final;
?></span></td>
</tr>
</table>
<p> </p></td>
</tr>
</table> <br><br />
<table width="95%" border="0" cellspacing="3" cellpadding="0" style="padding-top:5px">
<tr>
<td align="left" valign="top" class="style26"><a href="/spares.php"><img src="/images/continue.png" width="200" height="30" border="0" /></a></td>
<td width="100%" align="center" valign="top" class="style26"><a href="/cart/clearcart.php"><img src="../images/clear.png" width="200" height="30" border="0" /></a></td>
<td align="left" valign="top" class="style26"><form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display:inline">
<input type="hidden" name="cmd" value="_xclick" />
<input name="return" type="hidden" id="return" value="/cart/ordercompleted.php" />
<input type="hidden" name="business" value="***" />
<input type="hidden" name="item_name" value="Order :: Total £<?php echo $total_price; ?> " />
<input type="hidden" name="amount" value="<?php echo $total_price; ?>" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="no_shipping" value="2">
<input type="image" name="submit" src="/images/checkout.png" alt="Pay Now" />
</form> </a></td>
</tr>
</table>
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
</table></td></tr>
</table></td>
</tr>
</table>
</body>
</html>
<?
mysql_close($con);
}
?>
Thanks in advance..:~)