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.
firstlly - load jquery
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.
the first two javascript snippets go in your
the php snippet is a file referenced in the jquery
the <div> is somewhere in your html and represents the div to be refreshed by the php and javascript
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.
firstlly - load jquery
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.
the first two javascript snippets go in your
the php snippet is a file referenced in the jquery
the <div> is somewhere in your html and represents the div to be refreshed by the php and javascript
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(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>
<?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;
?>
<div id="divToRefresh"></div>

Getting into this Ajax stuff finally, just submitted a bare bones ajax loader for my future use. http://code.hyperspatial.com/all-code/javascript-code/ajax-request/