anthelo Posted March 17, 2011 Share Posted March 17, 2011 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 https://forums.phpfreaks.com/topic/230908-show-article-only-if-date-is-current-or-later/ Share on other sites More sharing options...
bh Posted March 17, 2011 Share Posted March 17, 2011 Hello, What is the type your NewsDate column? Link to comment https://forums.phpfreaks.com/topic/230908-show-article-only-if-date-is-current-or-later/#findComment-1188623 Share on other sites More sharing options...
anthelo Posted March 17, 2011 Author Share Posted March 17, 2011 Type: Date Default: 0000-00-00 Link to comment https://forums.phpfreaks.com/topic/230908-show-article-only-if-date-is-current-or-later/#findComment-1188634 Share on other sites More sharing options...
aabid Posted March 17, 2011 Share Posted March 17, 2011 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 https://forums.phpfreaks.com/topic/230908-show-article-only-if-date-is-current-or-later/#findComment-1188652 Share on other sites More sharing options...
void Posted March 17, 2011 Share Posted March 17, 2011 why are you using colons in your date() function then? wouldn't date("Y-m-d") do the trick? Link to comment https://forums.phpfreaks.com/topic/230908-show-article-only-if-date-is-current-or-later/#findComment-1188700 Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2011 Share Posted March 17, 2011 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 https://forums.phpfreaks.com/topic/230908-show-article-only-if-date-is-current-or-later/#findComment-1188709 Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2011 Share Posted March 17, 2011 just noticed that I neglected to remove the quotes around CURDATE(), the quotes shouldn't be there . . . Link to comment https://forums.phpfreaks.com/topic/230908-show-article-only-if-date-is-current-or-later/#findComment-1188713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.