It's really not that difficult as it sounds, and it's even easier with jQuery.
What you need is a PHP script which takes care of fetching the data.
server.php (Dummy code, and you will prolly be using PDO etc.)
Code: Select all
$query = mysql_query(fetch some data, where uid == $_POST['uid']);
$row = mysql_fetch_row($query);
print $row['gold'];
So running this script, giving the post query string is set, will print out gold.
Next we need a Javascript that polls this page.
data_fetcher.js
Code: Select all
// We need to keep polling, as we do not know if there is any data to fetch.
setTimeout(function() {
// Let's use jQuery's Ajax API, which makes it a walk in the park.
$.ajax({
type: "POST",
url: "server.php", // Correct the path.
data: { uid: 3 } // Set the user id here.
}).done(function( data ) {
// In the data variable, we get whatever, was printet in server.php
$('.gold').html(data); // Update the gold, in markup.
});
// Poll, every 5000 miliseconds (5 seconds).
}, 5000);
This code is not tested at all, but should give you a good ide how you can handle it.
