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

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').

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.