Automated content load?

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hello,

How can I get Ajax to automatically load a piece of content when it's sent to a database?
For instance: Person A sends a message to Person B, at which point Ajax sees that the message has been sent and automatically loads it onto the page for Person B.

Can someone please help me with this?

Thanks a lot!
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,147
2,469
I'd say this is rather anoying for Person B, however this can be done with PHP. You would need to add a column 'is_read' to the database of the messages, and with AJAX you can reload the page every x seconds like the DevBest shoutbox does to check it.

$query = mysql_num_rows("SELECT * FROM messages WHERE is_read='0' AND reciever_user_id='".$userid."' ");
if ($query >= 0)
{
header('Location: messages.php?message_id=idhere');
}

This is just a little code to do it, I'm a bit tired now, if it doesn't work I'll check it out tomorrow for you.
 

Users who are viewing this thread

Top