So you have a div that you would like to be up to date on your site without having the page refresh? This small script will allow you do this. Let's say that you want to show the total number of users on your site as your site is blowing up and you want visitors to see the number grow. firstly...load jquery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
next, we need to build the script in the "head" section of your page. This script targets a div with a loaded php file and sets how often the div should be reloaded
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function() {
$('#divToRefresh').load('/path/to/your/php/file/userCount.php');
}, 3000); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
});
// ]]></script>
here are the contents of "userCount.php"
require "/path/to/your/database/connection/connection.php";
$userCount = mysql_query( "SELECT * FROM users" ) or die("SELECT Error: ".mysql_error());
$numRows = mysql_num_rows($userCount);
echo $numRows;
here is the div in the html. you can place "loading users..." or a "loading" image inside of the div and it will be replaced by the results of "userCount.php"
<div id="results">Loading users...</div>