Last updated January 25, 2011. Created on January 5, 2011.
Edited by Pav. Log in to edit this page.

These are instructions on how to create a drop down which links to already created custom CCK fields.
In our example we have two content types 'Association' which describes an organization with many other fields like their address, etc. And 'Data' which describes information gathered about many Associations. The drop down we need will be in 'Data' type. It will be used to select an association name which is pulled from a number of already created entries of 'Association' type.

1. You need to have Option Widgets module enabled in your CCK. Administrer->Site Building->Modules->Option Widgets under CCK

2. In your Content Type (the one where you are going to have the drop down - e.g. 'Association' content type) just add new field (e.g. field_association_name) and select text, then select-list field. Administer->Content Management->Content Type->Manage Fields

3. Create a Node View which lists whatever you want in the drop down (e.g. field_association_name content) from the content type you want to list ('Association' content type). To do this in Views select Fields and add (+ plus sign) Content: Name (field_association_name) Text - Appears in: Association.
In Filters select Node Type ('Association'). This should list all instances of 'Association' type.

Test your View by clicking Preview button in views. It should return the names of associations. Copy the Select statement returned by the View for use later.

4. Go to your content type where you want your drop down ('Data' content type). Configure the newly created (in point 2) select-list filed and scroll down to Global settings, Allowed Values and in the part where you can add PHP code and add:

In the below PHP code you will need your SQL query which you can get from running "preview" in your created View you should have a copy of it from point 3 above.
It should be something like this :

SELECT node_data_field_association_name.field_association_name_value AS node_data_field_association_field_field_association_field_va,
node.type AS node_type,
node.nid AS nid,
node.vid AS node_vid
FROM node node
LEFT JOIN content_type_association node_data_field_association_field ON node.vid = node_data_field_association_field.vid
WHERE node.type in ('association')

'title' in the template below would be replaced by node_data_field_association_field_field_association_field_va. It has to be the part following the Select statement in your SQL statement which your SQL returns.

Template would be something like this:
$sql = "Your SQL query you can take from Views";
$res = db_query($sql);
while($row = db_fetch_array($res)){
$rows[$row['title']] = $row['title'];
return $rows;

Your drop down should be included the field_association_name from type 'Association' as value and in the list while creating 'Data' content.

Hope this helps.

Looking for support? Visit the forums, or join #drupal-support in IRC.


Nissx’s picture

Doesn't work for me :(

I think I'm getting stuck on this part:

$sql = "Your SQL query you can take from Views";
$res = db_query($sql);
while($row = db_fetch_array($res)){
$rows[$row['title']] = $row['title'];
return $rows;

Doesn't return the list.

This is my SQL:

SELECT node.nid AS nid, node_data_field_name.field_name_value AS node_data_field_name_field_name_value, node.type AS node_type, node.vid AS node_vid FROM node node LEFT JOIN content_field_name node_data_field_name ON node.vid = node_data_field_name.vid WHERE node.type in ('teacher')

Pav’s picture

Hi have you fixed it? When you try the preview in you View what does it return? Please check this if it doesn't return check your filter and that you have content with the right type and that the date field name has been populated.

If the preview of the View returns what you want then maybe check the "title" so in your case the line:
$rows[$row['title']] = $row['title']; should be:

$rows[$row['node_data_field_name_field_name_value']] = $row['node_data_field_name_field_name_value'];

If you still have the issue after doing the above checks post the whole code and I'll try to help.
Sorry for the late reply but I was away,