bennybwoi Posted December 26, 2009 Posted December 26, 2009 Hello Im Just Getting Into The World Of PHP. I was wondering whats the codes to show how many people are online and signed up on your site, i wish to put it on a login page, so any ideas ????? i will be thankful for any help as i am new to this. :) Thanks, Benny Bwoi! Quote
Danny696 Posted December 26, 2009 Posted December 26, 2009 Is it mccodes? if so, use this: $numb = $db->num_rows($db->query("SELECT userid FROM users")); echo'Members: '.number_format($numb); $online = $db->num_rows($db->query("SELECT userid FROm users WHERE laston>(unix_timestamp()-15*60)")); echo'There are '.number_format($online).' users online.'; Quote
bennybwoi Posted December 26, 2009 Author Posted December 26, 2009 um so how would you do this for a html login? bt still for mccodes? Quote
Zero-Affect Posted December 27, 2009 Posted December 27, 2009 $numb = $db->fetch_row($db->query("SELECT COUNT(`userid`) AS `mem_count` FROM `users`")); echo 'Members: '.number_format($numb['mem_count']); $online = $db->fetch_row($db->query("SELECT COUNT(`userid`) AS `on_count` FROM `users` WHERE `laston` > (unix_timestamp()-15*60) ")); echo 'There are '.number_format($online['on_count']).' users online.'; just a little edit hope you don't mind. :S Quote
Danny696 Posted December 27, 2009 Posted December 27, 2009 The SQL function COUNT has been un-reliable for me, so i use $db->/mysql_num_rows instaad Quote
Zeggy Posted December 27, 2009 Posted December 27, 2009 The SQL function COUNT has been un-reliable for me, so i use $db->/mysql_num_rows instaadCOUNT is unreliable if you use the innodb engine. If you use myISAM then it should work fine. Using COUNT is generally better as it lets mysql do the counting (faster). If you use mysql_num_rows, all the rows and the row data are fetched. This would be fine if you are using that row data at the same time (such as in a member list), but if you're only looking for the number of rows, then it's a huge waste of resources. Instead, you could keep the row counts in a separate table, which is just a counter that is incremented any time you insert a row. Or just deal with the inaccuracies of COUNT. What kind of data is so important that you really need an exact count of the rows in a table? Quote
Zero-Affect Posted December 27, 2009 Posted December 27, 2009 COUNT as always worked for me so sorry if it doesn't on some of yours Using COUNT is generally better as it lets mysql do the counting (faster). If you use mysql_num_rows, all the rows and the row data are fetched. This would be fine if you are using that row data at the same time (such as in a member list), but if you're only looking for the number of rows, then it's a huge waste of resources. ^exactly Quote
Gwink Posted December 28, 2009 Posted December 28, 2009 Just my 2 cents here : If you have no traffic NEVER use an onsite counter to show you have no traffic to everyone... I don't know why new webmasters always start a website by a visible counter : It's like a big info sign saying "Aye I'm a new webmaster and this is my first site with no traffic, signup to play alone now!" :) If that's not the case here sorry for posting for nothing :S Quote
bennybwoi Posted December 28, 2009 Author Posted December 28, 2009 Just my 2 cents here : If you have no traffic NEVER use an onsite counter to show you have no traffic to everyone... I don't know why new webmasters always start a website by a visible counter : It's like a big info sign saying "Aye I'm a new webmaster and this is my first site with no traffic, signup to play alone now!" :) If that's not the case here sorry for posting for nothing :S LOL thanks m8t xD Quote
Zero-Affect Posted December 28, 2009 Posted December 28, 2009 Just my 2 cents here : If you have no traffic NEVER use an onsite counter to show you have no traffic to everyone... I don't know why new webmasters always start a website by a visible counter : It's like a big info sign saying "Aye I'm a new webmaster and this is my first site with no traffic, signup to play alone now!" :) If that's not the case here sorry for posting for nothing :S Sounds fun actually where do i signup? lol but on a serious note i get what your saying if you have a low member base then there's no point in a counter but if you have a high member base then it's always a good thing to show off. Quote
bennybwoi Posted December 28, 2009 Author Posted December 28, 2009 hmmm i want to space both statistics from eachover because atm its shows like this, There are: - Member.There are - users online., wont work, hw can i space it to look lik this There are: - Member. There are - users online.? Quote
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.