Jump to content

SELECT statement - display current month only


Panavision

Recommended Posts

FROM (tblNews LEFT JOIN tblNews_Picture ON tblNews.News_ID = tblNews_Picture.News_ID),  

tblAuthor WHERE tblNews.Author_ID = tblAuthor.Author_ID  

 

My problem is to DISPLAY news items where tblnews.newsdate = CURRENT MONTH. Also, how do I display news from previous months (for archive)?

Link to comment
Share on other sites

I tried this and didn\'t work, geez I suck at SQL statements :cry:

 

$news=mysql_query(\\\"SELECT *

FROM (tblNews LEFT JOIN tblNews_Picture ON tblNews.News_ID = tblNews_Picture.News_ID),  

tblAuthor WHERE tblNews.Author_ID = tblAuthor.Author_ID  

 

AND tblNews.NewsDate = month(now())

 

Help please... :?:

Link to comment
Share on other sites

I tried this and didn\'t work, geez I suck at SQL statements  :cry:  

 

$news=mysql_query(\\\"SELECT *

FROM (tblNews LEFT JOIN tblNews_Picture ON tblNews.News_ID = tblNews_Picture.News_ID),  

tblAuthor WHERE tblNews.Author_ID = tblAuthor.Author_ID  

 

AND tblNews.NewsDate = month(now())

 

Help please... :?:

 

Try and show us a:

 


select * from tblNews LIMIT 5;

 

Your problem is probably comparing a DATE to a MONTH ? SO yuo should format your tblNews.Newsdate to a month (dependent on format) as well...

 

Probably


$news=mysql_query("SELECT * 

FROM (tblNews LEFT JOIN tblNews_Picture 

ON tblNews.News_ID = tblNews_Picture.News_ID), tblAuthor 

WHERE (tblNews.Author_ID = tblAuthor.Author_ID)

AND (

MONTH(tblNews.NewsDate) = MONTH(CURDATE())

)";

 

will do the job... (HINT: if your NewsDate is a varchar - well you just need a number from [1, 12] to compare with the MONTH(CURDATE()), which returns a number [1,12])

 

P., denmark

Link to comment
Share on other sites

Thanks, I did solve it in the end doing something similar :)

 

What if I wanted to check against, say JULY 2002?

 

 

news=mysql_query("SELECT * 

FROM (tblNews LEFT JOIN tblNews_Picture ON tblNews.News_ID = tblNews_Picture.News_ID), 

tblAuthor WHERE tblNews.Author_ID = tblAuthor.Author_ID 



AND MONTH(tblNews.NewsDate = month******)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.