gianniskpf
gianniskpf

Reputation: 93

automatically change an html item when something changes in the database

I have this code:

$resource=mysql_query("SELECT * FROM messages WHERE user='$id'");
$num=mysql_num_rows($resource);

if ($num==0) echo '<li><a style="color:red">messages (0)</a></li>';
else echo '<li><a style="color:blue">messages ('.$num.')</a></li>';

It searches into the database and if it finds new messages for the user, it changes the colour of the font, displaying the number of unread messages. the problem is that the page has to be refreshed first and this is not happening automatically.

Unfortunately, auto-refresh is not an option.
Can i use AJAX? would perl do any good?

Thanks

Upvotes: 0

Views: 117

Answers (1)

JMax
JMax

Reputation: 26591

You can use a setInterval() or a setTimeout() to call regularly an AJAX function that would make a call to your server

Upvotes: 1

Related Questions