I need simply to count all users and show this number somewhere on the page (many be main) of in the hand-made block. I found some useful query
//prepare amount of users
$count_users_tot = db_fetch_array(db_query("SELECT COUNT(uid) FROM {users}"));

but how can I insert in this php-style page? Help, please, I'm php-dummy.

Comments

kuba.zygmunt’s picture

where do you want to put this information ?

in a special block ?
or something in your page (theme template)

Continental’s picture

I think both. Does it really matter? I want to write to the main page: "We're ... 1'000'000'000 users =)" and somewhere in block like "Total users: 3" to show it on different pages I choose.

so,
it should be special block and
it should be php-code I insert along other informatino on the main (custom page). not theme! I don't want it to show everythere.

kuba.zygmunt’s picture

so use PHP filter in your custom block or page, and add the following code:

$count_users_tot = db_result(db_query("SELECT COUNT(uid) FROM {users}"));

echo $count_users_tot;

ps. sorry for not answering for a such time :/

Continental’s picture

thank you. =) It wasn't priority, but now I have a nice statistics block... I also need to count photos from gallery (menalto) in the same way, if anybody can get me a tip how to do it I'll really appreciate it (however, it's only hald drupal issue... mostly gallery).

soccernyc’s picture

Plugged your code in a block and it worked beautifully! Exactly what I needed....

Thanks.

andrenoronha’s picture

how can I count only authenticated users?

haleagar’s picture

$count_users_tot = db_result(db_query("SELECT COUNT(uid) FROM {users} where status > 0"));

Hal Eagar
Software Architect
hal.eagar@door3.com

red2006135’s picture

Would this work with drupal 7.7

im having errors when i paste your codes on a block and have a php code config.

thank you.

john_b’s picture

<?php
$count_users_tot = db_query('SELECT COUNT(uid) FROM {users} where status > 0')->fetchField();
print $count_users_tot;
?>

(remove line break!)

Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors

jsibley’s picture

Is there a way to save this in a view in the header, without any fields? If so, what is the correct view format that will accept the code without requiring any fields to save it?

john_b’s picture

I do not really understand why you want to use a view. However there is a module which allows you to add a custom php field to a view. This code in a custom php field could, I am guessing, be the only field in your view.

Obviously you can display the out of a view which has a 'block' display in your header, if your theme has a header region.

Digit Professionals specialising in Drupal, WordPress & CiviCRM support for publishers in non-profit and related sectors

haopei’s picture

Hello kuba. Is there a way to modify this to only display the number of users of a certain role?