Jump to content

mysql timestamp


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...