How to fill CCK SELECT BOX with PHP

I found the lack of documentation also confusing (and time-consuming). You need to return an array like this:

$array["value"] = "label";

For instance:

<?php
$result = db_query(db_rewrite_sql('SELECT nid,title from {node} WHERE type="page"'));
while ($item = db_fetch_object($result)) {
   $items[$item->nid] = $item->title;
}
return $items;
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <b> <address> <blockquote> <br> <caption> <center> <code> <dd> <del> <div> <dl> <dt> <em> <font> <h2> <h3> <h4> <h5> <h6> <hr> <i> <img> <li> <ol> <p> <pre> <span> <strong> <sub> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <u> <ul> <tr>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use the special tag [adsense:format:group:channel] or [adsense:block:location] to display Google AdSense ads.

More information about formatting options

To combat spam, please enter the code in the image.