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.
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
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>