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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Problem getting chained membership data
Pages: [1]

Author Topic: Problem getting chained membership data  (Read 668 times)

wingfingerbill

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 4.4.14
  • CMS version: WordPress 4.1.1
  • MySQL version: 5.6.23
  • PHP version: 5.5.23
Problem getting chained membership data
August 07, 2012, 03:13:01 am
Hi

Trying to get all individual contacts with more than 1 membership entry.

Code: [Select]
$params = array(
'contact_is_deleted' => 0,
'contact_type' => 'Individual',
'api.membership.get' => array('count' =>2),
'version' =>3,
rowCount => -1
);

$contacts = civicrm_api('Contact','Get', $params); //
print_r($contacts);


As you can see, I don't know how to request results where count > 1, so I'm using count==2 instead.

Main problem, though, is that I'm getting all the individual (non-deleted) contacts back - together with their memberships info.  How do I limit the results based on number of memberships?

Thanks

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Problem getting chained membership data
August 07, 2012, 01:51:48 pm
I can't see a way to do this from the API - you're looking to do a query ending in

HAVING count => 2 which I can't see how to do - the api doesn't really do GROUP BY queries.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

wingfingerbill

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 4.4.14
  • CMS version: WordPress 4.1.1
  • MySQL version: 5.6.23
  • PHP version: 5.5.23
Re: Problem getting chained membership data
August 07, 2012, 02:19:10 pm

Quote
I can't see a way to do this from the API - you're looking to do a query ending in

HAVING count => 2 which I can't see how to do - the api doesn't really do GROUP BY queries.

OK. I'll do it the long-winded way.

Thanks anyway

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Problem getting chained membership data
August 07, 2012, 07:36:31 pm
eileen used this on one of our sites to give me a list of people with more than one membership so am sharing it for anyone looking for an sql but it may not help if you are then trying to use the API

Code: [Select]
ELECT no_memberships, m.contact_id, display_name, m.id as membership_id, mt.name, start_date, join_date, status_id, end_date  FROM civicrm_membership m

LEFT JOIN civicrm_contact c on c.id = m.contact_id
LEFT JOIN civicrm_membership_type mt ON mt.id = m.membership_type_id
INNER JOIN (
SELECT count(*) as no_memberships, contact_id
FROM civicrm_membership m

GROUP BY contact_id
HAVING no_memberships > 1) as doubles
ON doubles.contact_id = c.id
ORDER BY c.id
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

wingfingerbill

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 4.4.14
  • CMS version: WordPress 4.1.1
  • MySQL version: 5.6.23
  • PHP version: 5.5.23
Re: Problem getting chained membership data
August 08, 2012, 02:50:39 am
Thanks Pete

I might try the direct sql approach for next time - but I find sql a lot less intuitive/familiar than php, so it takes me longer to get my head round what's going on.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Problem getting chained membership data

This forum was archived on 2017-11-26.