Cannot write a complete function to compare current month and year to my database m/y. The dates in the database are from the now() function. I want to sum the costs based on this comparison. Something like:
$currentDate = date("Y-m");
$query = mysql_query ("SELECT SUM(cost) FROM memberorders WHERE
memberNumber=$memNum AND
(SELECT DATE_FORMAT(orderDate, '%Y-%m'))=$currentDate");
But that’s not working. Then I need help with a function to sum it up.
$test1 = mysql_fetch_array($query);
$total = $test1[0];
Would that work for going through the database and summing it up?
Don’t do that, don’t apply any function (like the
DATE_FORMAT()function) to a column (like theOrderDatecolumn) if you want indexes to be used. Try this if you can create the fixed starts of months in the application (PHP) code:or this if you prefer to handle it in MySQL: