Sniffy Posted June 11, 2007 Share Posted June 11, 2007 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 More sharing options...
justsomeguy Posted June 11, 2007 Share Posted June 11, 2007 $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 More sharing options...
Sniffy Posted June 11, 2007 Author Share Posted June 11, 2007 wow, thank you. I think i am starting to understand what the sql aliases are used for. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.