0

I'm creating this form with checkboxes that I want to populate from a database. The problem is, how do I create an array of key=>value pairs when the data I need to create the pairs is in an object? I'm not sure I'm explaining myself properly, heres' the code and hopefully it will be clearer:

function myform_form($form, &$form_state) {
  $options_query = db_query('SELECT name, mname FROM event_type');
  $options = array();
  foreach($options_query as $o) {
    $options(($o->mname) => ($o->name));  //This is where I get the error unexpected T_DOUBLE_ARROW
  }
  $form['options'] = array(
    '#type' => 'checkboxes', 
    '#title' => t('Search options'),
    '#options' => $options,
    '#description' => t('Choose what you want.'),
 );

Is there a way to do this?

1 Answer 1

2

Try changing:

  $options(($o->mname) => ($o->name)); 

to

 $options[$o->mname] = $o->name; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.