So, this is my code:
//Connect to the database
include("config.php");
//Query the database and get the count
$result = mysql_query("SELECT * FROM ads");
$num_rows = mysql_num_rows($result);
?>
How can I make it so it query's the database for the count every few seconds?
解决方案
Save your PHP script separately (in my example below thescript.php)
//Connect to the database
include("config.php");
//Query the database and get the count
$q = mysql_query("SELECT count(*) as num FROM ads");
$count = mysql_fetch_result($q,0,'num');
echo $count;
?>
Then use AJAX/javascript/jQuery in your home.php file:
$(function(){
function loadNum()
{
$('h1.countdown').load('thescript.php');
setTimeout(loadNum, 5000); // makes it reload every 5 sec
}
loadNum(); // start the process...
});