Statistic counter auto refresh div and mysql query
We are building live statistics counter, refreshing numbers every 10sec. (similar like stackoverflow questions counter). We have simple html page, we tried to embed php and tried to use jquery, but no success. Any help? Thanks
<html>
<script>
var auto_refresh = setInterval(
function() {
$('#stats').fadeOut('fast').fadeIn("fast");
},
10000
);
</script>
<div id="stats">
<?php
global $conn;
$query="SELECT count(*) as total FROM posts WHERE type='update'";
$query2="SELECT count(*) as total FROM members WHERE USERID>0";
$postnum = mysql_query($query);
$posts = mysql_result($postnum,0);
$chanid = mysql_query($query2);
$channels = mysql_result($chanid,0);
print "<div id='statnr'><h6> $channels </h6><h1>channels </h1> </div>";
print "<div id='statnr'><h6> $posts </h6><h1>posts </h1> </div>";
?>
</div>
</html>开发者_开发问答;
you're only fading the stats div out an in again. you have to make an ajax call to the php file getting the new data.
var auto_refresh = setInterval(
function() {
$.ajax(
url:"counter.php",
success:function(data){
$('#stats').fadeOut('fast', function(){
$(this).html(data).fadeIn('fast');
});
}
)
},
10000
);
精彩评论