hi, i use AJAX, framework - JQUERY.
Now all information show in one table( <div id = "user">).

var user= setInterval(function()
{
$('#user).load(user.php?id='+ Math.random());
}, 5000);

user.php:

$rez= mysql_query($sql, $db) or die("Error");
while($r = mysql_fetch_array($rez, MYSQL_ASSOC )){
$name= $r["name"]; 
$time= $r["time"];

But how make this:

$name show in div name, and $time show in div time.
One file, and two <div>
I hope to understand my trouble

Recommended Answers

All 3 Replies

Lola,

Try this:

var user = setInterval(function(){
	$.get( user.php, { id : Math.random() }, function (data) {
		data = data.split('||');
		$("name").html(data[0]);
		$("time").html(data[1]);
	});
}, 5000);
$rez= mysql_query($sql, $db) or die("Error");
$r = mysql_fetch_array($rez, MYSQL_ASSOC );
echo $r["name"] . '||' . $r["time"]
exit;

Note how '||' is used as a separator that allows the combined string returned by user.php to be re-split in javascript back into its component parts (name and time).

I've not tested so it may need debugging.

Airshow

Just found time to test.

Use this javascript in place of that posted above:

$(document).ready(function(){
	var user = setInterval(function(){
		$.get( 'user.html', { id : Math.random() }, function (data) {
			data = data.split('||');
			$("#name").html(data[0]);
			$("#time").html(data[1]);
		});
	}, 5000);
});

Airshow

thanks ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.