Displaying “New” text next to title in Web forums

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);

}

?>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.