-5

showing messages with:-

$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";
mysqli_query($con, $query);

unreaded message:-

$query = "SELECT status FROM chat WHERE status=0";
mysqli_query($con, $query);

status == 0 - unreaded

status == 1 - readed..

how to do the auto fetch message without reloading the page by using ajax??

Virb
  • 1,639
  • 1
  • 16
  • 25
Navas Naz
  • 3
  • 2

1 Answers1

0

As the Database connection's already done. i prefer it to be in separate file (if your using php) i.e. data.php or anything else.

Use the jQuery script to fetch the data from that connection i.e. from database without reloading the page. here's the code for that:

<script type="text/javascript" src="jquery.js">
<div id="show"></div>
<script>
  $(document).ready(function(){
     setInterval(function(){
        $('#show').load("data.php")
     }, 3000);
  });
<script>
suman heuju
  • 121
  • 3