avatar.alex Posted April 14, 2007 Share Posted April 14, 2007 I have a php user managment system and I want a script that would count how many users are in the database and also if users are online or not Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 14, 2007 Share Posted April 14, 2007 ok, firstly, if each user is on record in a table, then simply go SELECT User_ID FROM Table then go mysql_num_rows. thats the number of users, almost the same for onlin, simply have a field, that when a user logs in, it writes to that field, "logged in" or something, and go SELECT User_ID FROM Table WHERE Logged_In = 'logged in' then mysql_num_rows if you give a bit of code, ill do a quick example if you need gdlk Quote Link to comment Share on other sites More sharing options...
avatar.alex Posted April 14, 2007 Author Share Posted April 14, 2007 the table that the users are stored is called bl_admin I don't know if you need a field but I think its all adminid bigint(20) No auto_increment username varchar(255) No password varchar(255) No status int(11) No 3 name varchar(255) No validated int(11) No 0 keynode varchar(255) No email varchar(255) No css longtext No lastposttime bigint(20) No 0 bannedfromforum int(11) No 0 lasttime bigint(20) No 0 tsgone bigint(20) No 0 oldtime bigint(20) No 0 Quote Link to comment Share on other sites More sharing options...
avatar.alex Posted April 14, 2007 Author Share Posted April 14, 2007 also how would I display it??? thank you so much Quote Link to comment Share on other sites More sharing options...
avatar.alex Posted April 14, 2007 Author Share Posted April 14, 2007 can anyone help me please Quote Link to comment Share on other sites More sharing options...
avatar.alex Posted April 14, 2007 Author Share Posted April 14, 2007 would part of the code look something like SELECT bl_admin FROM Table WHERE username= 'logged in' Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted April 14, 2007 Share Posted April 14, 2007 avatar.alex, I'm working on some sample code for you to help you figure this out. I'll reply back in a little while with it. Quote Link to comment Share on other sites More sharing options...
avatar.alex Posted April 14, 2007 Author Share Posted April 14, 2007 thank you!!!! Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted April 15, 2007 Share Posted April 15, 2007 To count the number of users in the database you could run a query like this: $result= mysql_query("SELECT COUNT(*) FROM bl_admin") ... and then show it like this ... echo 'Total Users: '. mysql_result($result, 0); To show the number of users online, you could first set up a field in your bl_admin table that would track the last time a user performed an action (perhaps this is what your lasttime field is for?). The easiest way would be to have code included on each page that would update that information on each page reload. I'll assume you are using sessions to track users that are logged in. Something like: if($_SESSION['logged_in']){ $sql = "UPDATE bl_admin SET lasttime = NOW() WHERE username = '$username'; mysql_query($sql) or die(mysql_error()); } ... then to show the users that are online, you'll need to set a "timeout" value. This will set a period of inactivity that will determine if a user is no longer online. $timeout = 300; // in seconds // Get a timestamp for the timeout time $timestamp_limit = time() - $timeout; // Create and run the query $result = mysql_query("SELECT username FROM bl_admin WHERE UNIX_TIMESTAMP(lasttime) > $timestamp_limit; $result_numrows = mysql_num_rows($result); $result_array = mysql_fetch_array($result); for($i=0;$i < $result_numrows;$i++){ if($i == 0){ echo '# of Users Online: '.$result_numrows.'<br>'; echo 'Users Online: '; } echo $result_array['username'].','; } Quote Link to comment Share on other sites More sharing options...
avatar.alex Posted April 15, 2007 Author Share Posted April 15, 2007 thank you so much this is going to help me out alot... Quote Link to comment Share on other sites More sharing options...
avatar.alex Posted April 30, 2007 Author Share Posted April 30, 2007 it says there are errors...if the lasttime field wasn't for the last time someone logged in what would I have to add and how would I display that. Quote Link to comment 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.