Auto-refresh Echo
I have a code: Here appear total users registered and I want to auto refresh this, for example if appear 100, when som
Solution 1:
A php varible is only rendered to the screen as the page is being preprocessed. Rather than have the echo there you'll want to use AJAX to fetch the user count.
$.ajax({
type : 'GET',
url : 'user_count.php',
success : function(data){
$('#refresh').html(data);
},
});
The example above is using jQuery's ajax method. You could call this in a timer and echo out the user count in user_count.php. This would then set the contents of refresh with the count gathered from the AJAX request.
Hope this made sense and helped you.
Tim
Solution 2:
$(function(){
setInterval(function(){
$("#refresh").load("registered_users_count.php");
}, 10000);
});
Solution 3:
An Ajax call is the better way to go but as a quick easy alternative you can have a simple php file like this:
<html><head><metahttp-equiv="refresh"content="5" /></head><body><?phpecho$users; ?></body></html>
and have it in a small <iframe>
in your main page.
Post a Comment for "Auto-refresh Echo"