how to link a select field options with the database records 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, &amp;$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-&gt;nid] = $row-&gt;sku;

    }


Query for record display

 $query = db_select('formmodule_order', 'h')
   -&gt;fields('h',array('nid','sku','orderIn','orderOut','created'))
   -&gt;orderBy('h.nid', 'ASC')
   -&gt;condition('$options[$row-&gt;nid]', array('pen-11'));

    $result = $query-&gt;execute();
Check out the Form API reference, especially the part about select lists:

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


You can also consult the examples module for more information.