Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Or better yet, transform this script in a function, and make it available site wide by having this file included in each page.
Then getting that number would simply be
PHP Code:
$users=countUsers();
in any page to fetch the current user count.
How to transform the script in a function you might ask?
Take this code for example:
PHP Code:
<?php $users=0; $query="select count(*) as cnt from users where activ=1"; $r=mysql_query($query); while($o=mysql_fetch_object($r)){ $users=$o->cnt; }
To transform this in a function, simply add the definition at the beginning, and return the value you fetched:
PHP Code:
<?php function userCount(){ $users=0; $query="select count(*) as cnt from users where activ=1"; $r=mysql_query($query); while($o=mysql_fetch_object($r)){ $users=$o->cnt; } return $users; }
And then a simple
PHP Code:
<?php print userCount();
will fetch the value and display it.
__________________
Only a biker knows why a dog sticks his head out the window.
|