Simple Name Simple Name - 3 months ago 20
Javascript Question

PHP Get Data From MySQLI [delete this]

Hello I'm trying to get live data from sql table, example if one rows is inserted show me with data like notification system

with my code when i insert new row not fetch me... !?

index.php:

<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function() {
setTimeout(
function() {updateChat();},
1000);

function updateChat() {
$.get("read.php", function(data)
{
$("#Show_Data").html(data);
});
}
});
</script>
<div id="Show_Data"></div>


read.php

include('config.php');

$sql_query = mysqli_query($connection, "SELECT * FROM shout_box where id > 15 ORDER BY id");

while($fetch_data = mysqli_fetch_array($sql_query, MYSQLI_ASSOC)) {
echo 'ID: ' .$fetch_data['id']. ' Text: '. $fetch_data['text']. '</br>';
}

mysqli_close($connection);


enter image description here

Answer

Use setInterval

var myCall = setInterval(updateChat, 1000);

//for to stop calling
function myStopFunction() {
   clearInterval(myCall);
}

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).

The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.

Comments