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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • API needed to retrieve address info from database
Pages: [1]

Author Topic: API needed to retrieve address info from database  (Read 1396 times)

maarten

  • Guest
API needed to retrieve address info from database
March 21, 2008, 11:41:05 am
In order to retrieve and display in a custom node the phone and address info of a CiviCRM Contact ($contact_id) I have this query:
Code: [Select]
$result = db_query("
    SELECT cp.phone,
     ce.email,
     ca.street_address,ca.postal_code,ca.city,ca.geo_code_1,ca.geo_code_2,
     csp.name AS state,
     cc.name AS country
      FROM civicrm_location AS cl
      LEFT JOIN civicrm_phone AS cp
      ON cl.id = cp.location_id
      LEFT JOIN civicrm_email AS ce
      ON cl.id = ce.location_id
      LEFT JOIN civicrm_address AS ca
      ON cl.id = ca.location_id
      JOIN civicrm_state_province AS csp
      ON ca.state_province_id = csp.id
      JOIN civicrm_country AS cc
      ON ca.country_id = cc.id
      WHERE cl.entity_table = 'civicrm_contact'
        AND cl.entity_id = %d
        AND cl.is_primary = 1
        AND ce.is_primary = 1
        AND cp.is_primary = 1
    ",
  $contact_id
  );
(note: I don't really need the geo code info)

My drupal modul is not working properly since I've upgraded to CiviCRM 2.0. The database schema has changed in CiviCRM 2.0. I would like to program this nicer using a proper API.

What would be a better way to retrieve address and phone info from the database? Is there an API for this?

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: API needed to retrieve address info from database
March 21, 2008, 12:03:41 pm
APIs docs are here: http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs

In particular, here is the api docs on contacts: http://wiki.civicrm.org/confluence/display/CRMDOC/Contact+APIs
You will probably want to use the Search APIs. civicrm_contact_search( &$params ) allows you define which properties you want to display.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • API needed to retrieve address info from database

This forum was archived on 2017-11-26.