Web design, programming, graphics, and pretty much anything else I care about.

Discover CCK field table and column information

When retrieving information from the database for CCK fields, you can't assume the schema. Fields may be added to the content table, but if they are included on more than one content type, they get moved to their own table. Because things might move around, you can't make assumptions about where they will be. CCK api has functions you can use to determine where things are located.

// Get the Drupal field and table info.
// We need to do this because the content type might have been altered.
$field_info = content_fields('field_name', 'my_content_type');
$db_info = content_database_info($field_info);
$table_name = $db_info['table'];
$column_name = $db_info['columns']['value']['column'];

You now have the column name and table name to use when running MySQL queries.