cobusbo Posted January 20, 2015 Share Posted January 20, 2015 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? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 20, 2015 Share Posted January 20, 2015 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. Quote Link to comment Share on other sites More sharing options...
cobusbo Posted January 20, 2015 Author Share Posted January 20, 2015 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 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 20, 2015 Share Posted January 20, 2015 Personally I'd do it with javascript. Each request for the new posts should include a timestamp of when that batch was received. Then when the data comes back just highlight everything > previous timestamp. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 20, 2015 Share Posted January 20, 2015 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. Quote Link to comment Share on other sites More sharing options...
cobusbo Posted January 20, 2015 Author Share Posted January 20, 2015 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 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 20, 2015 Share Posted January 20, 2015 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. Quote Link to comment Share on other sites More sharing options...
cobusbo Posted January 20, 2015 Author Share Posted January 20, 2015 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 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 20, 2015 Share Posted January 20, 2015 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. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 20, 2015 Share Posted January 20, 2015 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.