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')
->fields('h',array('nid','sku','orderIn','orderOut','created'))
->orderBy('h.nid', 'ASC')
->condition('$options[$row->nid]', array('pen-11'));
$result = $query->execute();