i am doing some experiments within my custom form and that is to display a table record from database only corresponding to the product code (i.e sku) is selected from the select list. The database has following structure:

nid | sku | orderin | orderout | created

I want to link the sku in select list and the sku in database table so that when i select a sku then data corresponding to that sku should only display. Below is what I have done so far.

Query for the select list

function formModule_display($form, &$form_state)

  // The form we are building
  $form = array();

 $result = db_query("SELECT o.nid, o.sku FROM {formmodule_order} o ");

    $options = array();
   foreach($result as $row) {
      $options[$row->nid] = $row->sku;


Query for record display

 $query = db_select('formmodule_order', 'h')
   ->orderBy('h.nid', 'ASC')
   ->condition('$options[$row->nid]', array('pen-11'));

    $result = $query->execute();
  • is there any method so that i can link the $options[$row->nid] = $row->sku; within the condition clause as this line of code - "->condition('$options[$row->nid]', array('pen-11'));" is giving error
    – aashi
    Commented Feb 12, 2013 at 7:19

1 Answer 1


Check out the Form API reference, especially the part about select lists:

   $form['selected'] = array(
       '#type' => 'select',
       '#title' => t('Selected'),
       '#options' => array(
          0 => t('No'),
         1 => t('Yes'),
       '#default_value' => $category['selected'],
       '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),

You can also consult the examples module for more information.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.