dean7 Posted May 21, 2009 Share Posted May 21, 2009 Hi all, I have a user online script witch my friend helped me with but it only counts the ammount of users online. <? session_start(); $session=session_id(); $time=time(); $time_check=$time-600; //SET TIME 10 Minute $host="***************"; // Host name $username="**********"; // Mysql username $password="********"; // Mysql password $db_name="*********"; // Database name $tbl_name="online_users"; // Table name // Connect to server and select databse mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE session='$session'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count=="0"){ $sql1="INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')"; $result1=mysql_query($sql1); } else { "$sql2=UPDATE $tbl_name SET time='$time' WHERE session = '$session'"; $result2=mysql_query($sql2); } $sql3="SELECT * FROM $tbl_name"; $result3=mysql_query($sql3); $count_user_online=mysql_num_rows($result3); echo "User online : $count_user_online "; // if over 10 minute, delete session $sql4="DELETE FROM $tbl_name WHERE time<$time_check"; $result4=mysql_query($sql4); mysql_close(); ?> But how would i make it so it would show the users that are online and count them at the same time? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/159142-online-users/ Share on other sites More sharing options...
MadTechie Posted May 21, 2009 Share Posted May 21, 2009 kinda need to know whats in the 'online_users' table, if you have usernames then a simple loop would work ie $sql3="SELECT * FROM $tbl_name"; $result3=mysql_query($sql3); //start add $users = array(); while($rows = mysql_fetch_array($result3)) { $users[] = $rows['user']; } var_dump($users); //output //end add $count_user_online=mysql_num_rows($result3); Quote Link to comment https://forums.phpfreaks.com/topic/159142-online-users/#findComment-839298 Share on other sites More sharing options...
dean7 Posted May 21, 2009 Author Share Posted May 21, 2009 In the user online table it has session and time. thats it. Quote Link to comment https://forums.phpfreaks.com/topic/159142-online-users/#findComment-839300 Share on other sites More sharing options...
MadTechie Posted May 21, 2009 Share Posted May 21, 2009 Your need to add UserName or UserID, then insert the UserName on logon Quote Link to comment https://forums.phpfreaks.com/topic/159142-online-users/#findComment-839339 Share on other sites More sharing options...
dean7 Posted May 21, 2009 Author Share Posted May 21, 2009 Do you know a way i could do that? Quote Link to comment https://forums.phpfreaks.com/topic/159142-online-users/#findComment-839369 Share on other sites More sharing options...
MasterACE14 Posted May 21, 2009 Share Posted May 21, 2009 INSERT or UPDATE a record in the table filling in the users, username and ID upon logon. Just throw in 1 extra query in your login script. Quote Link to comment https://forums.phpfreaks.com/topic/159142-online-users/#findComment-839469 Share on other sites More sharing options...
MadTechie Posted May 21, 2009 Share Posted May 21, 2009 Your need to add the fields to the table first Find the code that inserts into the online_users table and post that here Quote Link to comment https://forums.phpfreaks.com/topic/159142-online-users/#findComment-839482 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.