Jump to content

check for new news help..


UnknownPlayer

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/236556-check-for-new-news-help/
Share on other sites

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 />";
		}

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`";

 

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 ? :(

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.

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 :/

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.