get the problem to calculate the total amount of product
Posted: Fri Apr 15, 2011 8:41 am
hi, face some problem that cant calculate the total amount total quantity of all product in the cart..i also get another problem that the products in the cart it will display like this,if the cart table i have two products,it will display one product and total amount and total quantity of the product, and then it will display another product and total amount and total quantity of the product..it not calculate of these two product...can anyone help me to check and correct the code??thanks in advance..
Code: Select all
<?php
session_start();
require_once 'config.php' ;
require_once 'application.php' ;
$id = $_SESSION['id'];
$username = $_SESSION['username'];
$pid=$_REQUEST['pid'];
$pname=$_REQUEST['pname'];
$price=$_REQUEST['price'];
$quantity=$_REQUEST['quantity'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css">
<title>::View Cart::</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
<body>
<table width="952px" border="0" cellspacing="0" cellpadding="0" valign="top" align="center">
<tr>
<td align="center"><?php include "header.php"; ?></td>
</tr>
<tr><td><img src="picture/purple_line.jpg" /></td></tr>
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="300px" height="600px" valign="top" align="center"> <?php include "menu.php";?>
</td>
<td width="12px"> </td>
<td width="630px"background="picture/content1.png" style="background-repeat:no-repeat;" valign="top"><table width="100%" border="0">
<tr>
<td><table width="100%" border="0" align="right">
<tr>
<td width="28%"> </td>
<td width="38%"><img src="picture/icon_cart.jpg" /></td>
</tr>
</table></td>
</tr>
<tr><td><div align="center">
<table border="1"bgcolor="#FFFFFF">
<tr align="center">
<td width="80" bgcolor="#9710be"><font color="#FFFFFF">Item Name</font></td>
<td width="80" bgcolor="#9710be"><font color="#FFFFFF">Remove</font></td>
<td width="80" bgcolor="#9710be"><font color="#FFFFFF">Quantity</font></td>
<td width="80" bgcolor="#9710be"><font color="#FFFFFF">Price(RM)</font></td>
</tr>
<?php
$query = "SELECT * FROM cart WHERE id=$id";
$result = mysql_query($query);
while($row=mysql_fetch_object($result))
{
$quantity=$row->quantity;
$price= $row->price;
$pid=$row->pid;
$pname=$row->pname;
$totalup = $price * $quantity;
$total=0.00;
$totalQuantity=0;
?>
<tr><td> <font color="#000000">
<?php echo $row->pname;?>
</font></td>
<td width="80" align="center"> <form action="remove.php">
<table>
<tr>
<td align=center><font color="#000000">Quantity</font></td>
</tr>
<tr>
<td align="center" width="10" ><input type="text" name="quantity" value=""size="5"id=" $pid"></td>
</tr>
<input type="hidden" value = "<?php echo $row->pid;?>" name = "pid">
<tr>
<td><font color="#000000">
<input type="submit" value = "Remove">
</font></td>
</tr>
</table>
</form></td>
<td align=center><font color="#000000">
<?php echo $row->quantity;?>
</font></td>
<td><font color="#000000"><nobr>RM
<?php echo $row->price;?>
</nobr></font></td>
</tr>
</table>
</div>
</td></tr>
<?php $total += $totalup;
$totalQuantity += $quantity; ?>
<tr><td><div align="center"><font color="#FFFFFF"></font>
<table align="center
" width="350" border="2" cellpadding="0" cellspacing="0"bgcolor="#FFFFFF">
<tr>
<td width="165" height="50"><div align="center"><font color="#000000"><strong>Total
Amount :</strong></font></div></td>
<td width="80" align=center><font color="#000000">
<?php echo $totalQuantity;?>
</font> </td>
<td width="80"><font color="#000000">RM
<?php echo $total;?>
</font></td>
</tr>
<?php
}
?>
</table>
</div>
</td></tr>
<tr><td><table><tr><td width="350" align="right"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="130" height="28">
<param name="movie" value="button1.swf" />
<param name="quality" value="high" />
<param name="base" value="." />
<param name="bgcolor" value="#9900FF" />
<embed src="button1.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="250" height="35" bgcolor="#9900FF"></embed>
</object></td>
<td width = "100" align = " center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="108" height="28">
<param name="movie" value="button2.swf" />
<param name="quality" value="high" />
<param name="base" value="." />
<param name="bgcolor" value="#9900FF" />
<embed src="button2.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="108" height="28" bgcolor="#9900FF"></embed>
</object></td></tr></table></td></tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>