how to notify a user when a new sql record inserted?

1.4k Views Asked by At

I m working in a simple private messaging script using PHP and SQL , and I need I way to notify the user when a new message is received, maybe in a simple notification bar , something like this :

New Messages [ 6 ]

Here is the database

TABLE `messages` (
  `id` int(11) NOT NULL auto_increment,
  `user_1` int(11) NOT NULL,
  `user_2` int(11) NOT NULL,
  `message` text NOT NULL,
  `timestamp` int(10) NOT NULL )  

as you see , it's very simple.

any Ideas ?
Sorry for my terrible English, Have a good day.

1

There are 1 best solutions below

1
On

Make respective functions and Put conditions

if(InsertMessage())
{
  SendMessage();
}

function InsertMessage()
{
   //query and code to insert message 
   //return true if success 
   //return false if fail   
}

function SendMessage()
{
  //Code to send message
}