Jump to content

highlight newest post between refresh


cobusbo

Recommended Posts

Hi I'm currently wondering how people check for latest records each time they refresh only the latest records display in another color. For example a chat. When people submit post and another user refresh their chat page the newest post always get highlighted. Does it work with sessions or how does it work?

Link to comment
Share on other sites

It works anyway you want it to. How is the refresh done? By the user clicking something that triggers a POST? You can put something on the page to mark the last shown record and then highlight ones that succeed that on your next page build. You can use a datetime value for this, or a record id value.

 

It's really not an exact science - it's just some algorithm that you yourself make up and follow. The highlight is the easy part using css. It's the recognizing that you will have to work out for yourself.

Link to comment
Share on other sites

It works anyway you want it to. How is the refresh done? By the user clicking something that triggers a POST? You can put something on the page to mark the last shown record and then highlight ones that succeed that on your next page build. You can use a datetime value for this, or a record id value.

 

It's really not an exact science - it's just some algorithm that you yourself make up and follow. The highlight is the easy part using css. It's the recognizing that you will have to work out for yourself.

I'm currently printing the values from the database and when I click reload it just a hyperlink to the same page to reload it

Link to comment
Share on other sites

You will need to output your results using some html and css to do your highlighting. From what you wrote I'm guessing you are just echo'ing some query results. Try putting them into an html table or in an html list and use css to produce the highlighting.

 

echo "<table>";
while($row = $pdo->fetch())
{
   if ($row['datefld'] > $highlight_date)
       $classname = 'hilight';
   else
       $classname = 'normal';
      echo "<tr class='$classname'><td>{$row['field1']}</td><td>{$row['field2']}</td><td>{$row['field3']}</td></tr>";
}
echo "</table>";
You would need to set the value of the $highlight_date field based on something and write a couple of css classes to achieve your highlight or normal effects.
Link to comment
Share on other sites

You will need to output your results using some html and css to do your highlighting. From what you wrote I'm guessing you are just echo'ing some query results. Try putting them into an html table or in an html list and use css to produce the highlighting.

 

echo "<table>";
while($row = $pdo->fetch())
{
   if ($row['datefld'] > $highlight_date)
       $classname = 'hilight';
   else
       $classname = 'normal';
      echo "<tr class='$classname'><td>{$row['field1']}</td><td>{$row['field2']}</td><td>{$row['field3']}</td></tr>";
}
echo "</table>";
You would need to set the value of the $highlight_date field based on something and write a couple of css classes to achieve your highlight or normal effects.

 

the problem is the timestamp since last reload how would I be able to get that timestamp to compare it against the new post when I press reload since I only got timestamps of when the message was inserted into the db

Link to comment
Share on other sites

Most chat applications that I've seen don't sent HTML back. They send JSON (which is a lot more compact), and then the javascript builds the HTML based on the values from the JSON data and inserts it into the DOM. The timestamp can easily be a field in the JSON data.

Link to comment
Share on other sites

Most chat applications that I've seen don't sent HTML back. They send JSON (which is a lot more compact), and then the javascript builds the HTML based on the values from the JSON data and inserts it into the DOM. The timestamp can easily be a field in the JSON data.

the problem is I must do it without javascript the since its not supported on the platform im using

Link to comment
Share on other sites

You decide. You could use the data's saved date/time value and send the latest one out on the web page as a hidden field in your form. Or you could just send the current date/time. When the web page is submitted/posted back to your script you get that hidden value and use it as your compare value for when you build the new/refreshed page.

Link to comment
Share on other sites

multiple posts can be made in the same second you are running a query to retrieve posts. by using the timestamp, you can miss new posts, that then show up in the next update as read, but where never shown as unread/new.

 

you need to use the auto-increment id of the highest record that was displayed in the last update to find 'new' posts in the next update. see this reply for more info - http://forums.phpfreaks.com/topic/292925-if-mysql-table-updated-since-page-load/?hl=%2Bsmf&do=findComment&comment=1498777

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.