0

Reloading page when new message received by the user not working.

I am developing a PHP chat application. Where admin and users can chat.

When new message arises, the user needs to reload the page and fetch the new message from the database.

My query is:-

$query = "SELECT * FROM `chat` 
    WHERE fromthe = '$email' and tothe='theadmin' 
    UNION ALL SELECT * FROM `chat`
    WHERE fromthe = 'theadmin' and tothe='$email' order by id desc";   
$sql1 = "UPDATE `chat` SET `status`='1' where tothe='$email'";
         mysqli_query($con, $sql1);

Please help me to do it.

Thanks

GYaN
  • 2,327
  • 4
  • 19
  • 39
fazal za
  • 11
  • 3

1 Answers1

0

You can either use setInterval and hit the database every x second to check for new message wish is a really bad practice , or use websocket

Abslen Char
  • 3,071
  • 3
  • 15
  • 29