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) »
  • Multiselect custom data representation in MySQL
Pages: [1]

Author Topic: Multiselect custom data representation in MySQL  (Read 949 times)

jperickson

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
Multiselect custom data representation in MySQL
October 27, 2010, 09:34:36 pm
Hello. I am trying to insert selections from a drupal form into a custom data field that is a multi-select field in Civi. The values are represented with numbers separated with what I think is the null byte. The problem is that I can't find a way to insert that separater systematically. Does anyone know how to produce that separator?

Thank you for your help!

neha

  • I’m new here
  • *
  • Posts: 10
  • Karma: 1
  • CiviCRM version: v3.4, v4.0
  • CMS version: Drupal 6 / 7, Joomla 1.5 / 1.6
  • PHP version: php 5.3
Re: Multiselect custom data representation in MySQL
October 28, 2010, 04:20:55 am
jperickson

Multi select values stored in database are separated using CRM_Core_DAO::VALUE_SEPARATOR. It is already handled in civicrm code base
You have to arrange the multi select values in an array that have to be stored into database.
The civicrm codebase will automatically implode the array values with the separater.

Consider the following example,

Code: [Select]
require_once 'api/v2/Contact.php';
$params = array( 'custom_9' => array( 0 => 'value1', 1 => 'value4' ),
                              'contact_id'  => 127,
                              'contact_type' => 'Individual');
        
$contact = civicrm_contact_update($params);

Here the custom_9 is the multi select custom field and value1 and value4 are the values selected.

HTH

Neha
« Last Edit: October 28, 2010, 04:22:48 am by neha »

jperickson

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
Re: Multiselect custom data representation in MySQL
October 28, 2010, 05:41:18 pm
Great. Thank you for the information! What's the easiest way to read that data out of the db? I'm using a multiselect as a custom field for an event, and I would like to be able to retrieve the selected values in PHP. Thank you again!

neha

  • I’m new here
  • *
  • Posts: 10
  • Karma: 1
  • CiviCRM version: v3.4, v4.0
  • CMS version: Drupal 6 / 7, Joomla 1.5 / 1.6
  • PHP version: php 5.3
Re: Multiselect custom data representation in MySQL
October 28, 2010, 10:59:42 pm
jperickson,

Could you go through the civicrm APIs
http://wiki.civicrm.org/confluence/display/CRMDOC31/CiviCRM+Public+APIs
That will give you more insight on how to get data from civicrm database for the particular component

Neha

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Multiselect custom data representation in MySQL

This forum was archived on 2017-11-26.