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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.