Hey all,
I have a simple query I want to run that totals the cost of expenses for a given month. here's the query:
<?
// Get the Month and Year for the report
$month = $_GET['month'];
$year = $_GET['year'];
// Get all information for the requested month and year.
$query = "SELECT id, fulldate, category, description, cost, SUM(cost) FROM expenses WHERE month='".$month."' AND year='".$year."' ORDER BY fulldate";
$result = mysql_query($query, $db);
?>
And here is the part that it says creates an invalid MySQL resource record. It occurs later in the document.
<?
while($rpt = mysql_fetch_array($result, MYSQL_ASSOC)){
$id = $rpt['id'];
$category = $rpt['category'];
$fulldate = $rpt['fulldate'];
$cost = $rpt['cost'];
$description = $rpt['description'];
$total = $rpt['SUM(cost)'];
echo "<tr>";
echo "<td>".$fulldate."</td><td>".$category."</td><td>".$description."</td><td><p align=right>$".$cost."</td>";
echo "</tr>";
}
?>
The script works fine and dandy when I remove the SUM() function from the query and displays all the information correctly. Any help is greatly appreciated!
Thanks.