I am trying to retrieve all rows that are present within a table before the time the person has visited the page and there after update the div with any rows of data that has been added to the table since the user has been on the page.(Something like Whatsapp where the entire convo is visible and new messages get added to the bottom).
This is what I have so far using Ajax but I have no clue where I am going forward from this stage. It currently brings up only the newest record (IF I SET THE TIMESTAMP MANUALLY IN THE SECOND FILE) but not all the other records before it. Ideally I should work by posting the time to the second file.
How could I modify my code to get the functionality I desire?
Display (autoload.php)
var time = (new Date).getTime();
var interval = 1000; // 1000 = 1 second, 3000 = 3 seconds
function doAjax() {
$.ajax({
type: 'POST',
url: 'autoload2.php',
dataType: 'json',
data: 'time='+time,
success: function (data) {
$('.inner').append(data);
},
complete: function (data) {
setTimeout(doAjax, interval);
}
});
}
setTimeout(doAjax, interval);
Get data (autoload2.php)
$time = $_POST['time'];
$results = mysql_query("SELECT post_name FROM posts WHERE postime > $time limit 1");
$row = mysql_fetch_assoc($results);
$res = $row['post_name'];
echo json_encode($res);
Note: The time being used to query above doesn't work, only when it is hardcoded with the timestamp.