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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.