UnderGROUND
22-04-2007, 08:38 AM
Thanks to Mentor, I now have a goo ajax reload. Anyway, I have a script which says how many users are online, and the ajax displays it and updates every 10 seconds. Anyway, I have it set to refresh every 10 seconds, and it deletes users from the database as soon as they're inactive, but I want it so it does it when they're not on the page. So say there are 3 users online: User 1 goes to the page, (it's a game, so they can't keep reloading the page), user 2 is also at the page and 3 is. So it displays 3 users online. Then 10 seconds later, it deletes from the database, so it says there is 0 users on. But they are still at the page and are actually on.
I want it so it says they're on when they're at the page, and for it to only delete them from the list/database when they actually leave the page. Heres the code:
<?
/**
*
* TG WHO'S ONLINE
* Copyright 2005 - 2006 (c) TOXIC GOBLIN
* http://www.toxicgoblin.com
*
*/
//Optional Database Connection Information
//**Uncomment the following 2 lines and edit the values if you do not already have an active database connection**
//
//$db = mysql_connect("localhost", "username", "password") or die("Could not connect");
//mysql_select_db("database_name");
include 'config.php';
//Fetch Time
$timestamp = time();
$timeout = $timestamp - 10;
//Insert User
$insert = mysql_query("INSERT INTO TG_whos_online (timestamp, ip, file) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')") or die("Error in who's online insert query!");
//Delete Users
$delete = mysql_query("DELETE FROM TG_whos_online WHERE timestamp<$timeout") or die("Error in who's online delete query!");
//Fetch Users Online
$result = mysql_query("SELECT DISTINCT ip FROM TG_whos_online") or die("Error in who's online result query!");
$users = mysql_num_rows($result);
//Show Who's Online
if($users == 1) {
print("There is $users user online!\n");
} else {
print("There are $users users online!\n");
}
?>
As you can see it deleted them every 10 seconds, and updates the page so it says they're not there unless they refresh - then they're there again for 10 seconds. But I want it so they're on when they're at the page, and no on when they're not on it, but I want it to update instantly.
I hope you understand what I'm on about, anybody with good coding knowledge or in the know of a code, please help. :)
Thanks!
Edited by Lµke (Forum Moderator): Thread Moved from Website Designing. Please post in the correct section next time, Thanks :).
I want it so it says they're on when they're at the page, and for it to only delete them from the list/database when they actually leave the page. Heres the code:
<?
/**
*
* TG WHO'S ONLINE
* Copyright 2005 - 2006 (c) TOXIC GOBLIN
* http://www.toxicgoblin.com
*
*/
//Optional Database Connection Information
//**Uncomment the following 2 lines and edit the values if you do not already have an active database connection**
//
//$db = mysql_connect("localhost", "username", "password") or die("Could not connect");
//mysql_select_db("database_name");
include 'config.php';
//Fetch Time
$timestamp = time();
$timeout = $timestamp - 10;
//Insert User
$insert = mysql_query("INSERT INTO TG_whos_online (timestamp, ip, file) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')") or die("Error in who's online insert query!");
//Delete Users
$delete = mysql_query("DELETE FROM TG_whos_online WHERE timestamp<$timeout") or die("Error in who's online delete query!");
//Fetch Users Online
$result = mysql_query("SELECT DISTINCT ip FROM TG_whos_online") or die("Error in who's online result query!");
$users = mysql_num_rows($result);
//Show Who's Online
if($users == 1) {
print("There is $users user online!\n");
} else {
print("There are $users users online!\n");
}
?>
As you can see it deleted them every 10 seconds, and updates the page so it says they're not there unless they refresh - then they're there again for 10 seconds. But I want it so they're on when they're at the page, and no on when they're not on it, but I want it to update instantly.
I hope you understand what I'm on about, anybody with good coding knowledge or in the know of a code, please help. :)
Thanks!
Edited by Lµke (Forum Moderator): Thread Moved from Website Designing. Please post in the correct section next time, Thanks :).