I have a Ruby script which is constantly updating a MySQL database. I want to show the "mysql_num_rows()" in realtime. So as an entry is entered into the database by the Ruby script I want the PHP script to update its mysql_num_row() count in realtime.
I tried using , but I don't think this is the best solution.
Does any one have a better solution?
解决方案
Use JavaScript on the page to periodically make a call to the server and get some data. Using the jQuery library for cross-browser support of AJAX, you would simply do this:
jQuery(function($){
setInterval(function(){
$.get( '/getrows.php', function(newRowCount){
$('#rowcounter').html( newRowCount );
});
},5000); // 5000ms == 5 seconds
});
That will make a request to your server every 5 seconds and stick the result of whatever you send back into an element with an id of rowcounter, e.g.
There are xx rows in the DB.