MySQL Forums
Forum List  »  Newbie

Total up values in table & remove item
Posted by: Colin Roberts
Date: May 25, 2005 02:18AM

Would appreciate your comments,

how do you total up values in a table ? and remove an item from a basket table ?

Have query which returns several items from a table, however would like to sum the total value (costs) of all the items.

//code to select items with relevant basketid
$sql="select * from basket where basketrefno='$nextbasketid';";
$data=mysql_query($sql,$dbh) or die("error 3");

//setting up variable from checkbox within table, if client ticks check box
//when basket.php refreshed would remove this item from the basket ?
//not sure how to do this part
$quantity = $HTTP_POST_VARS["quantity"];

//setting up table headers
echo "<form name='updatebasket' method='post' action='basket.php?yourbasketid=$nextbasketid'>";
echo "<table border=3 bordercolor=green><tr><td><center>Picture</td>";
echo "<td>BID</td><td><center>Product</td><td><center>Title</td><td><center>Price</td>";
echo "<td>Qty</td><td>Total Cost</td><td>Remove</td></tr>";

//query to return all relevant records
while ($item = mysql_fetch_assoc($data))
{
echo"<tr><td><img src='images/" . $item["picturename"] . "'></td>";
echo "<td>" . $item["basketrefno"] . "</td><td><b>" . $item["partnumber"] . "</b></td>";
echo "<td>" . $item["title"] . "</td>";
echo "<td><font color=red><b>" . "£" . $item["price"] . "</b></font></td>";
echo "<td>" . "<input name='quantity' type='text' size='2' value=" . $item["quantity"] . "></td>";
echo "<td><b>" . "£" . $item["price"]*$item["quantity"] . "</b></td>";
echo "<td><input type='checkbox' name='remove' value='1'>" . "</td>";
}
echo "</table>";

I would like to sum up the 'Total Cost' fields to give a running total of the basket - how do you do this please

I would also like the functionality to be able to remove any item from the basket, if somebody ticks the checkbox, I have a 'Update' button on the which refreshes the page.

Many Thanks

Options: ReplyQuote


Subject
Written By
Posted
Total up values in table & remove item
May 25, 2005 02:18AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.