I think it is mainly a display problem that I am having. I have pasted the code below.
I want to generate a table with the categories listed, along with the sum of the columns related to those categories, limited to the date range specified. The query statement works from the command line, but I am having problems displaying the data. The table would look something like this for a particular date range:
Attendance at workshops & presentations: 304
Federal grants administered: 32
Hours in consultation: 228
Other grants administered: 12
Workshops and presentations: 13
The problem that I am having is echoing the aliases from the select statement. If I just echo each alias with a $row['alias'], I get something like this:
Attendance FedGrants Hours Other Wkshps
Attendance at workshops.... 304 0 0 0 0
Federal grants.... 0 32 0 0 0
Hours in ...... 0 0 228 0 0
Other grants ..... 0 0 0 12 0
Workshops ..... 0 0 0 0 13
Here is the code for the display.
<center><table cellpadding='10' border ='1'>
<tr>
<td>
<?php
mysql_connect("myserver.com", "myusername", "mypassword") or
die ("Could not connect to mysql database");
mysql_select_db("tracker") or
die ("Could not connect to statistics database");
$query = "SELECT category, datereceived, sum(hours) AS shours, sum(fedgrants) AS sfg, sum(stgrants) AS ssg, sum(workshops) AS sws, sum(attendees) AS satt FROM transactions WHERE DATE_FORMAT(datereceived, '%Y-%m') >= '$beginning' AND DATE_FORMAT(datereceived, '%Y-%m') <= '$ending' GROUP BY category";
$result = mysql_query($query) or
die ( mysql_error() );
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "Attendance at workshops & presentations: " . $row['satt'] . "<br><br>";
echo "Federal grants administered: " . $row['sfg'] . "<br><br>";
echo "Hours in consultation with librarians/citizens: " . $row['shours'] . "<br><br>";
echo "State grants administered: " . $row['ssg'] . "<br><br>";
echo "Workshops and presentations: " . $row['sws'] . "<br><br>";
echo "</td></tr>";
}
?>
</table></center>