PDA

View Full Version : New Posts Forum Question


Al_90
02-21-2006, 12:36 AM
with my forum i want the user to be able to see different icons if the post is new, any ideas on how to do it? right now i am using

<?
if (isset($_SESSION['username']))
{
$sql_query = mysql_query("SELECT time from users WHERE username = '" . $_SESSION['username'] . "'");
$my_time = mysql_fetch_array($sql_query);
$user_time = $my_time['time'];
if ($topic_locked == 'yes' && $topic_time > $user_time) { ?>
<img src="images/new_locked_icon.gif" width="25" height="25">
<? } elseif ($topic_locked == 'yes' && $topic_time < $user_time) { ?>
<img src="images/locked_icon.gif" width="25" height="25">
<? } elseif ($topic_locked == 'no' && $topic_time > $user_time) { ?>
<img src="images/new_regular_icon.gif" width="25" height="25">
<? } elseif ($topic_locked == 'no' && $topic_time < $user_time) { ?>
<img src="images/regular_icon.gif" width="25" height="25">
<?
}
}
?>

and topic_time is assigned above in the code, i just didnt include it. many thanks

chump2877
02-21-2006, 12:53 AM
record the time using time() in your database when a new post is submitted....in your forum code, compare the time in the database with the current time...if the current time is less than (for example) 12 hours later than the submit time, you could attach a "new post" image to the thread....after 12 hours, the "new post" image would disappear....

For example (this example changes the price in a catalog after one month's time):

$today = time();

if ($today > $time_added + (31 * 24 * 60 * 60))
{
echo '<a href="contact.shtml" class="pl2">Contact us</a> for Price and Availability.';
}
else
{
echo '$' . $price;
}

Al_90
02-21-2006, 01:28 AM
i understand that completly, but when the user views the topic, i want the icon to go back to normal because it is not new anymore, thanks

chump2877
02-21-2006, 02:05 AM
In that case, probably the best way to do this is to use some application of cookies : http://us3.php.net/manual/en/function.setcookie.php...

thesavior
02-21-2006, 02:18 AM
or have one spot in the table with the time the last post happened, then on the topic view, update a table with the current time. Then just compare the two times.

Al_90
02-21-2006, 02:25 AM
both are good option, but iv when iv got around 455 topics thats a lot of cookies and how on earth do i manage that many? do any of you know how phpbb or vbulletin does it?

chump2877
02-21-2006, 02:30 AM
You only have to set a cookie after someone visits a "new topic"...I doubt that a single user will read through every post on your forum....

And you can access your cookies throught the array $_COOKIE ....

Al_90
03-06-2006, 11:29 PM
would you mind giving me an example script using the cookie way