0
votes

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 :)

1
I solve it by array_push(). Thanks :)Rajeev Kumar

1 Answers

1
votes

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.