Smackie Posted February 7, 2007 Share Posted February 7, 2007 Hello forum people I'm using my friends account since i knew his password and i cant get ahold of him and i was wondering on how to make a simple Registered User Count from database Thank you Friend of Smackie's Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 7, 2007 Share Posted February 7, 2007 This might work for what you want <?php $sql = mysql_query("select * FROM users"); $nrows = mysql_num_rows($sql); echo $nrows; ?> Quote Link to comment Share on other sites More sharing options...
Smackie Posted February 7, 2007 Author Share Posted February 7, 2007 its not showing anything :S see i want it to be like We have 20 Registered users Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 7, 2007 Share Posted February 7, 2007 did you change the word users to your table name? this revision will check for any error in the sql: <?php $sql = mysql_query("select * FROM users")or die(mysql_error()); $nrows = mysql_num_rows($sql); echo $nrows; ?> Quote Link to comment Share on other sites More sharing options...
Smackie Posted February 7, 2007 Author Share Posted February 7, 2007 Alright thank you on that part now i just need help with one more thing.. i need help with Online (2 parts to it) please make them simple lol both parts in numbers... First part... i need a script where it shows how many users online (meaning Registered and Non Registered(or know as Guests) and the second part would be how many Online Registered users and i need one more thing i guess Most users ever online script too Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 7, 2007 Share Posted February 7, 2007 You will need to make another table to do this, and it isn't easy, but its not hard either. call it active_sessions You need 3 fields: session_id varchar(32); Null=yes; default=NULL last_access datetime; Null=yes; default=NULL ip varchar(25); Null=no; <?php $active_sessions = 0; $minutes = 5; // period considered active if($sid = session_id()) // if there is an active session { # DB connect here $ip = $_SERVER['REMOTE_ADDR']; mysql_query("DELETE FROM `active_sessions` WHERE `last_access` < DATE_SUB(NOW(),INTERVAL $minutes MINUTE)")or die(mysql_error()); $sql = mysql_query("SELECT * FROM active_sessions WHERE ip='$ip'"); $row = mysql_fetch_array($sql); if(!$row){ mysql_query("INSERT INTO `active_sessions` (`ip`, `session_id`, `last_access`) VALUES ('$ip', '$sid', NOW()) ON DUPLICATE KEY UPDATE `last_access` = NOW()")or die(mysql_error()); } $sessions = mysql_query('SELECT * FROM `active_sessions`')or die(mysql_error()); $active_sessions = mysql_num_rows($sessions); } echo'<b>Online Now: </b>'.$active_sessions; ?> This will show the total number of online people, you will need to add another field, and name it something like user and then modify the queries to insert or update a 1 for user and 0 for guest or something like that, then return all the 1's, and display that, and return all the 0's and display that. if you get my drift. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 7, 2007 Share Posted February 7, 2007 are you a php programmer yourself? have you written any of your code? we help with code, sometimes supply some examples, but you should be able to write a basic script that we can help with. now thelittleguy has been nice by writing all that for you. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted February 7, 2007 Share Posted February 7, 2007 he has been very nice. people pay good money for code. 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.