MySQL Forums
Forum List  »  PHP

Re: Help totaling a column
Posted by: Kevin Boaz
Date: April 22, 2006 03:35PM

Peter,
Thank you very much for the suggestion. It worked great. Much more simplier than the way I was trying. The new code that works.

<?
echo ("<title>Miscellaneous Items Inventory</title>")."\n";
echo ("<H2>Inventory of Miscellaneous Items")."\n";

$link = mysql_connect("xxxxxxxx","xxxxxxxx","xxxxxxxx") or die("Could not connect");
print "<br>"."\n";
mysql_select_db("invtest") or die("Could not select database");

$query = "SELECT Item_Number, Description, Quanity, Price, Extend_Price FROM inventory where catagory=7 and CHAR_LENGTH(Description)>0 ORDER BY Item_Number";
$result = mysql_query($query) or die("Query Failed");

print "<table border=3 cellpadding=10 cellspacing=1>\n";
print "<tr align=center valign=center>";
print "<td><align=center>Item Number</td>";
print "<td>Description</td>";
print "<td>Qty</td>";
print "<td>Price</td>";
print "<td>Total</td>";
print "<td>Inventory Qty</td>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t<td>&nbsp</td>\n";
print "\t</tr>\n";
}

$query = "SELECT SUM(Quanity), SUM(Price), SUM(Extend_Price) FROM inventory where catagory=7 and CHAR_LENGTH(Description)>0 ORDER BY Item_Number";
$result = mysql_query($query) or die("Query Failed");

print "<td></td>";
print "<td>Totals</td>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t<td>&nbsp</td>\n";
print "\t</tr>\n";
}
print "\t</table>\n";
return $data;
mysql_free_result($result);
mysql_close($link);

?>

Options: ReplyQuote


Subject
Written By
Posted
April 20, 2006 11:46PM
April 21, 2006 09:21AM
Re: Help totaling a column
April 22, 2006 03:35PM


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.