Jump to content

mysql timestamp


Sniffy

Recommended Posts

I am having a little issue with my php script. I only have three rows but with this script it says users online is 4, and when I remove the intval($getActive) I get "resource id #4 users online", why is this?

<?$openFile = fopen("userLog.txt", "a+") or exit("error");$contentsOfFile = fread($openFile, filesize("userLog.txt"));echo "&theLog=$contentsOfFile";include("dbConnect.php");$timeOnline = time() - (10 * 60);$getActive = mysql_query("SELECT COUNT(userName) FROM basicUserInfo WHERE lastActive>=$timeOnline") or die("error5");$updateFile = fwrite($openFile, " / " . intval($getActive) . " user(s) are online / ");fclose($openFile);?>

Link to comment
Share on other sites

$getActive is a MySQL resource, you can't use intval on it. It's returning the number 4 because that is what the resource ID is, not because that is the value of COUNT(userName). Give the field an alias and then reference it later.

$getActive = mysql_query("SELECT COUNT(userName) AS num FROM basicUserInfo WHERE lastActive>=$timeOnline") or die("error5");$row = mysql_fetch_array($getActive);$num_users = $row['num'];$updateFile = fwrite($openFile, " / " . $num_users . " user(s) are online / ");

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...