CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • how to get a civicrm 'contact-counter' in drupal?
Pages: [1]

Author Topic: how to get a civicrm 'contact-counter' in drupal?  (Read 565 times)

vantuykom

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: drupal
  • MySQL version: 5
  • PHP version: 5.3
how to get a civicrm 'contact-counter' in drupal?
September 06, 2014, 04:50:41 am
Hi,

in drupal, I have a drupal user counter in a block like this:

Code: [Select]
<?php
$members 
= db_query("SELECT count(uid) FROM {users} where uid > 0")->fetchField();
echo 
"Er zijn momenteel $members online leden";
?>
[code]

but how can I get the number of contacts from specific groups?

regards

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: how to get a civicrm 'contact-counter' in drupal?
September 06, 2014, 05:12:23 am
There are so many ways to do a simple count of contacts. Try this for example:

Code: [Select]
civicrm_initialize();
civicrm_api3('contact', 'getcount', array('group' => 3)); // will return count of contacts in group id 3
Try asking your question on the new CiviCRM help site.

vantuykom

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: drupal
  • MySQL version: 5
  • PHP version: 5.3
Re: how to get a civicrm 'contact-counter' in drupal?
September 06, 2014, 07:02:38 am
and can I set that in a drupal block? Is this PHP?
( I am not a coder)

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: how to get a civicrm 'contact-counter' in drupal?
September 06, 2014, 08:06:58 am
It is php. If you need the exact code to copy/paste into a drupal block, here it is (assuming you want group id 3 - change that to your group's actual id):
Code: [Select]
<?php
civicrm_initialize
();
$count = civicrm_api3('contact', 'getcount', array('group' => 3));
echo 
"Group 3 has {$count['result']} members.";
?>
Try asking your question on the new CiviCRM help site.

vantuykom

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: drupal
  • MySQL version: 5
  • PHP version: 5.3
Re: how to get a civicrm 'contact-counter' in drupal?
September 06, 2014, 08:23:07 am
Thank you,

I have tried your code, copy/pasted it in my block with php but it is not displaying the number, only 'group has members'

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: how to get a civicrm 'contact-counter' in drupal?
September 06, 2014, 10:13:13 am
Did you put in the correct group id?
You can insert
Code: [Select]
print_r($result); at the end to see what's going on.
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • how to get a civicrm 'contact-counter' in drupal?

This forum was archived on 2017-11-26.