webdogjcn Posted June 8, 2006 Share Posted June 8, 2006 [code] $year = date(Y); $month = date(m); $day = date(d); $hour = date(H); $minute = date(i);// Do this everythime I view a page in the forum mysql_query("UPDATE user_info SET log_year='$year' WHERE user_name='$user'"); mysql_query("UPDATE user_info SET log_month='$month' WHERE user_name='$user'"); mysql_query("UPDATE user_info SET log_day='$day' WHERE user_name='$user'"); mysql_query("UPDATE user_info SET log_hour='$hour' WHERE user_name='$user'"); mysql_query("UPDATE user_info SET log_minute='$minute' WHERE user_name='$user'");[/code][code] $minute_other= ($minute - 16); $minute++; $query=mysql_query("SELECT user_name FROM user_info WHERE log_year='$year' AND log_month='$month' AND log_day='$day' AND log_minute BETWEEN '$minute_other' AND '$minute'"); if (!$query){ echo"mysql_error()"; } echo"username: $user and minutes: $minute and $minute_other<br>"; $users=mysql_fetch_array($query); $all=implode(",", $users); echo"$all";[/code]Okay I have tried logging in as three different users but only the first one is listed and it gets listed twice. I have displayed the values of the different users login times and compaired them and they fit within the range defined in the BETWEEN statement. Quote Link to comment https://forums.phpfreaks.com/topic/11514-logged-in-users-list-for-forum/ Share on other sites More sharing options...
webdogjcn Posted June 8, 2006 Author Share Posted June 8, 2006 Now I am just getting:Warning: implode(): Bad arguments. in /home/www/altgames.awardspace.com/members/forums/index.htm on line 118[code]line 118: $all=implode(",", $users);[/code]I really need help! Quote Link to comment https://forums.phpfreaks.com/topic/11514-logged-in-users-list-for-forum/#findComment-43344 Share on other sites More sharing options...
.josh Posted June 8, 2006 Share Posted June 8, 2006 you are only fetching 1 row. you need to do like, a while loop[code]echo "online users: ";while( $users=mysql_fetch_array($query)) { echo $users['user_name']. " ";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11514-logged-in-users-list-for-forum/#findComment-43346 Share on other sites More sharing options...
webdogjcn Posted June 8, 2006 Author Share Posted June 8, 2006 Okay I did that and I noticed I wasn't adding in the hour to the query which caused some wierd problems. However, now it just displays nothing with the error:Warning: mysql_numrows(): supplied argument is not a valid MySQL result resourceWhich obviously means that nothing is being returned by the queryHere is the current code:[code]$minute_other= ($minute - 16);$minute++;$query=mysql_query("SELECT user_name FROM user_info WHERE log_year='$year' AND log_month='$month' AND log_day='$day' AND $log_hour='$hour' AND log_minute BETWEEN '$minute_other' AND '$minute'");$online=mysql_numrows($query);$i = 0;while($i < $online) {$users = mysql_result($query,$i,'user_name');echo $users['user_name']. " ";$i++;}[/code]It should work b/c what is set as the users log time is this:+-Year----Month----Day----Hour----Minute----++--2006----06--------08------17--------55-------+And the current timestamp is+--2006----06--------08------17--------56-------+So why is it not working? Quote Link to comment https://forums.phpfreaks.com/topic/11514-logged-in-users-list-for-forum/#findComment-43421 Share on other sites More sharing options...
Fyorl Posted June 8, 2006 Share Posted June 8, 2006 Firstly, just a quick tip: You don't have to put each update in a separate query, you can just do this:[code]mysql_query("UPDATE `user_info` SET `log_year`='$year', `log_month`='$month', `log_day`='$day', `log_hour`='$hour', `log_minute`='$minute' WHERE `user_name`='$user'");[/code]As for your actual problem, I'm assuming user_name is unique? In which case you don't need to use SQL to do your validation and can just use:[code]$minute_other = $minute - 16;$minute++$query = mysql_query("SELECT * FROM `user_info`");while($info = mysql_fetch_array($query)){if($info['log_year'] == $year && $info['log_month'] == $month && $info['log_day'] == $day && $info['log_hour'] == $hour && $info['log_minute'] >= $minute_other && $info['log_minute'] <= $minute){echo $info['user_name'] . '<br />';}}[/code]Let me know if that fixes your problem. Quote Link to comment https://forums.phpfreaks.com/topic/11514-logged-in-users-list-for-forum/#findComment-43428 Share on other sites More sharing options...
webdogjcn Posted June 9, 2006 Author Share Posted June 9, 2006 Yea, nevermind I figured it out...thanks everyone for the help Quote Link to comment https://forums.phpfreaks.com/topic/11514-logged-in-users-list-for-forum/#findComment-43443 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.