0

My code count and display total number of messages on index page.
I want to show only number of new messages. How to skip old messages or mark old messages as read?

CREATE TABLE IF NOT EXISTS `message` (
`id` bigint(50) NOT NULL AUTO_INCREMENT,
`name` tinytext NOT NULL,
`message` text NOT NULL,
PRIMARY KEY (`id`)
) ;

index.php

<script>
 $(document).ready(function() {
 	 $("#responsecontainer").load("MsgCount.php");
   var refreshId = setInterval(function() {
      $("#responsecontainer").load('MsgCount.php?randval='+ Math.random());
   }, 1000);
});
</script>

New messages ( <?php echo"<b id='responsecontainer'></b>"; ?> )

MsgCount.php

$query = mysql_query("SELECT * FROM message");
	 $num_rows = mysql_num_rows($query);
	 
	 echo"$num_rows";
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by chrishea
0

Add another field to your table where you can mark the message as read. Wherever you read a message in your code, immediately update that record and put the "read" value into the new field in that record. In your Select statement add a "where" clause that will ignore any messages previously read (e.g. where already_read<>'yes').

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.