How to alert the user of new posts

Okay let’s see if you guys can help me with this. I’ve searched on here but couldn’t find a topic similar to this but here’s what I want to do.

I want to alert the user when there are new posts to their feed (see image below). Now the image below is an html version of what I want to do…I’m having difficulty getting that into php/ajax or however. I have the following script:

<script type="text/javascript"> $(document).ready(function() { $.ajaxSetup({ cache:false }); setInterval(function() { $('#divToRefresh').load('dbcheck.php'); }, 500); }); </script>

<div id="divToRefresh">There are 12 new posts</div>

$sql3 = "SELECT keyword, timestamp FROM posts ORDER BY post_id DESC LIMIT 1;";
$query3 = $pdo->prepare($sql3);
$query3->execute();
$result3 = $query3->fetch();

$timestampCheck = time() - 120;
if ($result3['timestamp'] >= $timestampCheck)
{
echo "<div>There are 12 new posts!</div>\n\n";
}

(Please keep in mind that the phrase “There are 12 new posts” is only a filler. What would generally be there is: There are <?php echo $total; ?> new posts)

So all in all I’m trying to do something like this site does, doesn’t alert you but it tells you that there are new topics/posts

Also, should I post this question in a new topic/thread?

Thanks in advance guys :slight_smile:

Are you asking about how to make the Ajax/JavaScript trigger the reload of the new posts count, or how to determine how many new posts there are?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.