Accessing CCK field data (single, multiple, or shared) from another module
Last modified: March 27, 2007 - 15:14
note- this is taken from KarenS's post to the development list
To access data stored by CCK within another module, you need to determine which table it's stored in.
To find the right table for a field for a SQL query, use the CCK API, like this:
$db_info = content_database_info($field);
$table = $db_info['table'];That will always return the right table for the requested field.
$field needs to be the complete field array, not just the field name, so if you only have the field name, you would do:
$field = content_fields(my_field_name);
$db_info = content_database_info($field);
$table = $db_info['table'];content_database_info($field) also contains info about the columns declared by the field so you know what field names to use in a SQL query. It returns an array that looks like:
Array (
[table] => content_type_story
[columns] => Array (
[value] => Array (
[type] => varchar
[length] => 50
[not null] => 1
[default] => ''
[sortable] => 1
[column] => field_phone_value
)
[value2] => Array (
[type] => int
[length] => 10
[unsigned] => 1
[not null] => 1
[default] => 0
[column] => field_phone_type
)
)
)