Tuesday, September 8, 2009

Add a PHP script to CCK

If you want to add a CCK field with values which are available in other database tables, then you might just add the field , select drop down values , and in the allowed values, open the cascade to see PHP Values allowed.
In the textarea enter the code : ( no need for starting and ending tags)
-------------------------------------------------------------
$options = array('' => t('- select a product -'));
$res = db_query('SELECT title FROM {node},{uc_products} WHERE node.nid = uc_products.nid');
while ($o = db_fetch_object($res)) {
$options[$o->title] = $o->title;
}
return $options;
--------------------------------------------------

this will populate the drop down box with db enteries in products table with the product nodes

No comments: