Jump to content

Show article only if date is current or later


anthelo

Recommended Posts

I'm building an article system, what im trying to do is when a user choose the article to be published tomorrow to able to.  Write today the article but the system will show it from tomorrow

 

        $gettoday = date("Y:m:d");
$query = "SELECT * FROM tblnews WHERE MainArticle = 1 AND NewsDate = '".$gettoday."'  ORDER BY `Id` DESC LIMIT 1";
$result = mysql_query($query);

 

This is my code, but when i use this and the article is not posted for today is not showing anything.. any suggestions please?

 

Thank you

You can use mysql_num_rows function which returns the number of rows returned from your SQL Query. All you have to do is to set a if condition, if mysql_num_rows returns 0 then this means there is no post for today and then you can echo any message you want to be displayed to the user.

It sounds like when you run the SELECT query you only want the article displayed if the data is today's date, regardless of when it was entered in the database, correct? If so, don't bother with the php date() function. Use MySQL's CURDATE() function for the comparison.

 

SELECT * FROM tblnews WHERE MainArticle = 1 AND NewsDate = 'CURDATE()'  ORDER BY `Id` DESC LIMIT 1

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.