I'll paste the text below to show you what I'm talking about. I need to get the sum of the results of a previous query to output into and echo, and I'm getting stuck here. As you see in the first echo, row[1] is the pc_charge of that particular record. I need the sum of all the row[1] ouputs at the bottom of the page(shown in red). Please help! Thanks 🙂
<html>
<head>
<title>VAD Labor Charge Report</title>
<?
if ($submit) {
?>
<META HTTP-EQUIV=Refresh CONTENT="600">
<?
};
?>
</head>
<body bgcolor="#D5D5AB" text="#000000" link="#0000FF" vlink="#0000FF" alink="#00
00FF">
<div align="left">
<h2 align="left"><img src="/vad/Avnet_LSC.jpg" width="222" height="72"></h2>
<h2 align="left"><u><strong><font size="5">Labor Charge Report</font></strong></
u></h2>
</div>
<?
if (!$submit) {
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST">
What Month?<br>
<input name="month" type="text" size="10" maxlength="10"><p>
What Year?<br>
<input name="year" type="text" size="10" maxlength="4"><P>
<input type="submit" name="submit" value="Generate Report!">
<?
}
else
{
$host = "localhost";
$user = "aaron";
$db = "VADtest";
$connection = pg_Connect("host=$host dbname=$db user=$user");
if (!$connection) {
die("Could not open connection to the database server");
}
$query = "SELECT DISTINCT on (company) company, sum(pc_charge*quantity) from sh
ipper where month = '$month' and year = '$year' group by company";
$result = pg_query($connection, $query) or die("Error in query:$query. " . pg_l
ast_error($connection)); $rows = pg_num_rows($result);
if ($rows > 0)
{
for ($i=0; $i<$rows; $i++)
{
$row = pg_fetch_row($result);
?>
<li><font size="-1"><b><? echo $row[0]; ?></b></font>
<br>
<font size="-1"><? echo $row[1]; ?></font>
<p>
<?
}
}
else
{
?>
<font size="-1">No data available.</font>
<?
}
echo "Total PC Charge for $month $year is sum of row[1]";echo "Total PC Charge for $month $year is sum of row[1]";
pg_close($connection);
}
?>
<p align="left"> </p>
<a href="index.htm">Return to Main Menu</a>
</body>
</html>