Need to select all entries for todays date

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
elbejones
Forum Newbie
Posts: 4
Joined: Fri Apr 09, 2010 9:56 am

Need to select all entries for todays date

Post 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'];
	}

User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need to select all entries for todays date

Post 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'";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
elbejones
Forum Newbie
Posts: 4
Joined: Fri Apr 09, 2010 9:56 am

Re: Need to select all entries for todays date

Post by elbejones »

It was the quotes, Thanks.
Post Reply