Re: WHERE clause...getting closer

From: Date: Wed, 05 May 2004 08:05:58 +0000
Subject: Re: WHERE clause...getting closer
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-185401@lists.php.net to get a copy of this message
Ray Hunter wrote:
On Tue, 2004-05-04 at 19:18, msa wrote:
$query_rsENews = 'SELECT * FROM NewsArchive WHERE YEAR(datePublished) = ' . YEAR('NOW'()) . ' AND MONTH(datePublished) = ' . MONTH('NOW'()) . ' ORDER BY sortBy DESC'; this is supposed to return only the records that have the current month and year in the datePublished record. got this error: Fatal error: Call to undefined function: year()
You sure you did not mean $dataPublished?
I think datePublished is his columnName? But also: Assuming mySQL (I can't find your original post?): +++This is all wrong: mysql> SELECT YEAR('NOW'()); ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '())' at line 1 +++This is even worse, really: mysql> SELECT YEAR('NOW()'); +---------------+ | YEAR('NOW()') | +---------------+
|          NULL |
+---------------+ 1 row in set (0.00 sec) +++This is what you want: mysql> SELECT YEAR(NOW()); +-------------+ | YEAR(NOW()) | +-------------+
|        2004 |
+-------------+ 1 row in set (0.00 sec) So I'd guess at your syntax being: $query_rsENews = <<<_SQL SELECT * FROM NewsArchive WHERE YEAR(datePublished) = YEAR(NOW()) AND MONTH(datePublished) = MONTH(NOW()) ORDER BY sortBy DESC _SQL; HTH

« previous php.general (#185401) next »