View Single Post

  #5 (permalink)  
Old 11-29-2005
Christian Kirsch
 
Posts: n/a
Default Re: selecting by date

Peter schrieb:
> Suppose I have a month and a year (this is for a blog application):
>
> $month = 10; // October
> $year = 2005; // year 2005
>
> I'd like to select items on or before the last day of October 2005 in
> descending order. My first attempt was:
>
> echo "SELECT * FROM $tblPosts " .
> "WHERE MONTH(postDate)<=$month & YEAR(postDate)<=$year " .
> "ORDER BY postDate DESC, id DESC LIMIT $to_request");
>
> but for some reason, this is selecting ALL records.
>
>
> Given a month and year, how do I select any item with a postDate (which is a
> datetime field) on the last day of the month or earlier in the same year?


Try your query in mysql (the commandline tool) - PHP is irrelevant for
your question.
And brush up your SQL - the "AND" operator is definitely not "&".
Reply With Quote