Displaying “New” text next to title in Web forums
In web forums, we can display “New” text next to tiltles using the following example. Here we will select a title, the current date minus the DATE field which was set when the item was added to the database.
We’ll turn the sql result into a varialbe and check to see if it’s less than 15 (15 days old) and if it is, in the next if statement we’ll simply echo “New!!” next to the title.
This is handy for showing people new items in databases and pages.
<?
$sql_date = mysql_query(”SELECT title, TO_DAYS(now())-TO_DAYS(date) as date_diff FROM table WHERE id=’$id’”) or die (mysql_error());
while(list($title, $date_diff)=mysql_fetch_array($sql_date)){
if($date_diff < 14){
$new = “y”;
}
echo “Title: $title”;
if($new == “y”){
echo ” <font color=”red”>New!!</font>”;
}
mysql_free_result($sql_date);
unset($new);
}
?>
