I am trying to display an addition image next to an item if it was added to the database 3 days ago or less saying "new"?
In a table called movie there is a field called moviedateadded which stores when t开发者_StackOverflow社区he movie was added to the table in DATE format e.g. 2011-09-01.
I'm guessing I need to get the current date from the server, and use an if else statement to say if the moviedateadded is 3 days or less than the server time, echo out "new.jpg"?
Please confirm the best way to do this?
Thanks in advance.
<?php
$date = "2011-09-01";
if( (time() - strtotime($date)) > 3*24*60*60 ){
echo "More than three days";
}
?>
According to your code (edited also <= for 3 or less instead of more than 3
<?php
while($row = mysql_fetch_array($result)){
if( (time() - strtotime($row['moviedateadded'])) <= 3*24*60*60 ){
echo "<img src='images/twit.png'/>";
}
?>
<a href="movie.php?movieid=<?php echo $row['movieid']?>">
<img src="content/movie/<?php echo $row['movieimage'] ?>.jpg">
</a>
<?php
}
?>
精彩评论