Page 1 of 1

Need to select all entries for todays date

Posted: Fri Apr 09, 2010 10:13 am
by elbejones
personal accounting program - I need to get the sum of all the entries (mysql table) for today.
the date is inserted into the table in a date("Y-m-d") format
the table fields are id, date (type date) and amount
the code

Code: Select all

$current_date = date("Y-m-d");
$day_sum = day_sum($current_date);

function day_sum($today) {
		$q = " SELECT SUM(total) ";
		$q .= " AS sum_total";
		$q .= " FROM session";
		$q .= " WHERE date=". $today  ."";
		$r = mysql_query($q, $c);
	    confirm_query($r);
	    $day_sum = mysql_fetch_array($r);
	    return $day_sum['sum_total'];
	}


Re: Need to select all entries for todays date

Posted: Fri Apr 09, 2010 11:16 am
by AbraCadaver
First off the link identifier $c is not defined anywhere, and secondly you need to use quotes around the date in the query. Other than that, you didn't give any indication of the problem you're having or any errors.

Code: Select all

$q .= " WHERE date='$today'";

Re: Need to select all entries for todays date

Posted: Sun Apr 11, 2010 2:06 am
by elbejones
It was the quotes, Thanks.