UnknownPlayer Posted May 16, 2011 Share Posted May 16, 2011 I need to set when new news is posted from 7 days to now, to put echo that it is new.. while ($var = mysql_fetch_array($result)) { $name = $var['name']; $date = $var['date']; echo " - {$s_name} [new]<br />"; } Now i need to put "[new]" when news is written in past 7 days(1 week), can someone help me? Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/ Share on other sites More sharing options...
ohdang888 Posted May 16, 2011 Share Posted May 16, 2011 In your query, use DATEDIFF http://www.w3schools.com/sql/func_datediff_mysql.asp Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216084 Share on other sites More sharing options...
UnknownPlayer Posted May 16, 2011 Author Share Posted May 16, 2011 But i wonna list all, and put "[new]" text whitch is posted in last 7 days? :/ Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216104 Share on other sites More sharing options...
ohdang888 Posted May 16, 2011 Share Posted May 16, 2011 But i wonna list all, and put "[new]" text whitch is posted in last 7 days? :/ yes, so put that in your query DATEDIFF (NOW(), field ) AS diff and in the while while ($var = mysql_fetch_array($result)) { $name = $var['name']; $date = $var['date']; if($var["diff"] <= 7){ $new = "[new]"; }else{ $new = ""; } echo " - {$s_name} $new<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216106 Share on other sites More sharing options...
UnknownPlayer Posted May 16, 2011 Author Share Posted May 16, 2011 It always shows me [new] $query = "SELECT id, name, date, DATEDIFF ($time_now, date) AS diff FROM news"; What is the problem ? Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216154 Share on other sites More sharing options...
UnknownPlayer Posted May 16, 2011 Author Share Posted May 16, 2011 And date format is like: 1298912971 in db field date Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216164 Share on other sites More sharing options...
ohdang888 Posted May 16, 2011 Share Posted May 16, 2011 And date format is like: 1298912971 in db field date you're using UNIX, you need regular datetime, and NOW() gives you the current datetime use this exact query: $query = "SELECT `id`, `name`, `date`, DATEDIFF (NOW(), FROM_UNIXTIME(`date`)) AS diff FROM `news`"; Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216198 Share on other sites More sharing options...
UnknownPlayer Posted May 17, 2011 Author Share Posted May 17, 2011 Thank you very much, it works Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216484 Share on other sites More sharing options...
UnknownPlayer Posted May 18, 2011 Author Share Posted May 18, 2011 Hi, got problem On my computer where is installed apache , php, mysql it works, but on web server it does not work, got this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/dotars/public_html/online/shows.php on line 77 This is code: $query = "SELECT id, name, date, DATEDIFF (NOW(), FROM_UNIXTIME(date)) AS diff FROM shows ORDER BY name"; $result = mysql_query($query, $connection); What is problem here ? Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216941 Share on other sites More sharing options...
UnknownPlayer Posted May 18, 2011 Author Share Posted May 18, 2011 When i user or die (mysql_error())" i got this message: FUNCTION dotars_online.DATEDIFF does not exist How can i solve this ? :/ Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1216945 Share on other sites More sharing options...
ohdang888 Posted May 18, 2011 Share Posted May 18, 2011 When i user or die (mysql_error())" i got this message: FUNCTION dotars_online.DATEDIFF does not exist How can i solve this ? :/ what version of mysql? Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1217306 Share on other sites More sharing options...
UnknownPlayer Posted May 20, 2011 Author Share Posted May 20, 2011 MySQL client version: 4.1.22 ? Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1218214 Share on other sites More sharing options...
gizmola Posted May 20, 2011 Share Posted May 20, 2011 Yes DATEDIFF was added relatively recently. You can around this by using TO_DAYS(). SELECT id, name, date, (TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(date))) AS diff FROM shows ORDER BY name Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1218238 Share on other sites More sharing options...
PFMaBiSmAd Posted May 20, 2011 Share Posted May 20, 2011 LOL, datediff() was added to mysql 4.1.1 in 2004 and MySQL 4.1 Extended Support ended on December 31, 2009. Time to upgrade your mysql version. Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1218245 Share on other sites More sharing options...
gizmola Posted May 20, 2011 Share Posted May 20, 2011 LOL, datediff() was added to mysql 4.1.1 in 2004 and MySQL 4.1 Extended Support ended on December 31, 2009. Time to upgrade your mysql version. Haha, well I guess it's newer than I thought. With that said, the code I provided does the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1218247 Share on other sites More sharing options...
UnknownPlayer Posted May 22, 2011 Author Share Posted May 22, 2011 Yes DATEDIFF was added relatively recently. You can around this by using TO_DAYS(). SELECT id, name, date, (TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(date))) AS diff FROM shows ORDER BY name This helped.. thanks.. Support center from my hosting said that they have 5.1 version for new customers, they cant upgrade for old, becouse mysql can be broken or what :/ Quote Link to comment https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/#findComment-1218554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.