Jump to content
MakeWebGames

Counter Possible???


Recommended Posts

Posted

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!

Posted

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.';
Posted
$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

Posted
The SQL function COUNT has been un-reliable for me, so i use $db->/mysql_num_rows instaad
COUNT 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?

Posted

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

Posted

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

Posted

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
Posted
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.

Posted

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.?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...