Search code examples
drupaldrupal-6drupal-forms

Drupal 6 : Not populating select list from db_query()


I have made a custom form in a module where I have used a select list & I am trying to populate that with the name of OG name.

I wrote a function for db_query() & that is giving me exact out put but I am not able to populate that in from select.

Function for db_query():-

function taskform_project_select(){
    $options=array();
    $project_query = "SELECT node.title FROM {node}, {og} WHERE node.nid = og.nid";
    $project_details = db_query($project_query);
    while($project_title = db_fetch_object($project_details)){
        $options = $project_title->title;       
        dpm($options);
    }
    return $options;
}

Code in Form:-

  $options = taskform_project_select();
  $form['edproject'] = array(
    '#type' => 'select', 
    '#title' => t('Project'),    
    '#options' => $options,
    '#description' => t('Choose a project'),
    '#prefix' => '<td>',
    '#suffix' => '</td>',
  );

Thanks :)


Solution

  • Correct syntax is:

    $options[] = $project_title->title;
    

    ..with square brackets.

    $options[$project_title->title] = $project_title->title;
    

    provides a meaningful key value to the result. You could also retrieve the nid and use that as the key.