Page 1 of 1
Whos online script help???
Posted: Wed Mar 17, 2004 3:36 pm
by Joe
I am currently working on a who's online script but i have a problem. The method I am using is when a user logs in it adds 1 to the database column then the index page adds up all of the values and shows the total. The script is as follows:
<?php
$link = mysql_connect("???", "???", "???");
mysql_select_db("???") or die("Could not connect!" . mysql_error());
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$users = $row['active'];
mysql_query("SELECT add($users) FROM online") or die(mysql_error());
echo "<center>(There are ".$users." Currently online)</center>";
}
?>
Regards
Joe

Re: Whos online script help???
Posted: Wed Mar 17, 2004 3:40 pm
by TheBentinel.com
Joe wrote:I am currently working on a who's online script but i have a problem. The method I am using is when a user logs in it adds 1 to the database column then the index page adds up all of the values and shows the total.
What problem are you having? Is the counter not getting decremented when they log out, presumably because they don't actually log out, they just stop surfing or go somewhere else?
I think those "who's online right now" scripts usually are based on the time since the user was last active. So every time the user visits your site, you write a last-access time-date stamp to the user's profile. Then you pull up a list of everyone that has accessed your site in the past 5 minutes and call them "active". They may not be, they may have left, but there's no reliable way for you to know that. The time stamp is a reasonable guess.
Posted: Wed Mar 17, 2004 3:42 pm
by Joe
I have got all the timing sorted out and the works perfect. Its just the fact that it does not show how many users are actually online when i use this part:
echo "<center>(There are ".$users." Currently online)</center>";
I just get a plain old error. Please help
Regards
Joe

Posted: Wed Mar 17, 2004 4:51 pm
by coreycollins
What is your error message that you are getting?
In the mean time, try to put double quotes, " , around active in the line:
Re: Whos online script help???
Posted: Wed Mar 17, 2004 5:12 pm
by TheBentinel.com
Joe wrote:
Code: Select all
<?php
$link = mysql_connect("???", "???", "???");
mysql_select_db("???") or die("Could not connect!" . mysql_error());
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$users = $row['active'];
mysql_query("SELECT add($users) FROM online") or die(mysql_error());
echo "<center>(There are ".$users." Currently online)</center>";
}
?>
Agreed, we need the exact text of the error message to help you most.
Meanwhile, though, what is the mysql_query doing for you? Does it really populate the $users variable? I thought it would return a recordset that you would need to read through.
Posted: Wed Mar 17, 2004 8:27 pm
by Illusionist
try this:
Code: Select all
$res = mysql_query("SELECT add($users) as users FROM online") or die(mysql_error());
$res = mysql_fetch_assoc($res);
$users = $res['users'];
echo "<center>(There are $users Currently online)</center>";
Note: i haven't tested this actuall code, but im almost positive it'll work!!
Posted: Wed Mar 17, 2004 8:49 pm
by JAM
Sorry Joe, but that piece of code just doesn't look right.
Get ideas from here.
viewtopic.php?t=12980