SELECT *, SUM(units) subtotal FROM table GROUP BY date

- do you mean this?

Mike Smith wrote:

I'm trying to present a simple SELECT statement "GROUPED" by date.
Ex.
   WO    UNITS    OEM    COMMENTS    DATE
   123     10            Me        Notes                03/18/2003
   456     5              You       More Notes      03/18/2003
Total       15
...

I have it working grouping the dates together, but I can't seem to get the
Total Units for a group. You'll see  $body .= " instead of echo... because
this is sent as an email. Here is the relevent code:

<?php
//table headers
...
while($row = mssql_fetch_array($result)) {
// $row[10] = SHIP DATE (What I'm grouping by)
// $row[0] = Unit Qty (What I want to SUM, based on each "Group")

If ($lastship!='') { // skip the first record
If ($lastship!=$row[10]) {
$body .= "<tr>\n";
$body .= "<td><strong>Total</strong>\n";
$body .= "</td>\n";
$body .= "<td align=center><strong>$total</strong>\n";
$body .= "</td>\n";
$body .= "<td colspan=5>\n";
$body .= "</td>\n";
$body .= "</tr>\n";
$totqty=0;
$lastqty=0;

}
$total=0;
}

$totqty=$lastqty+$row[0];
$total = $totqty+$total;
$lastship = $row[10];
$lastqty=$row[0];

$body .= "<tr>\n";
$body .= "<td align=\"center\">\n";
$body .= "$row[11]\n";
$body .= "</td>\n";
$body .= "<td align=\"center\">\n";
$body .= "$row[0]\n";
$body .= "</td>\n";
$body .= "<td align=\"center\">\n";
$body .= "$row[1]\n";
$body .= "</td>\n";
$body .= "<td>\n";
$body .= "$row[12]\n";
$body .= "</td>\n";
$body .= "<td align=\"center\">\n";
$body .= "$row[8]\n";
$body .= "</td>\n";
$body .= "<td align=\"center\">\n";
$body .= "$row[9]\n";
$body .= "</td>\n";
$body .= "<td align=\"center\">\n";
$body .= "$row[10]\n";
$body .= "</td>\n";
$body .= "</tr>\n";

}
...
//close table, html
?>

Any help is appreciated.

Thanks,
Mike Smith







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to