Building a Custom Search block I have to search the entered text in a drupal table and if there is a match for the keyword get all the fields corresponding to that keyword. I have executed the query and I have the fields to be printed in a array called $column_name.

How can I display these fields to the user in the form of a table?

function module_form_submit($form, &amp;$form_state) {
$text = $form_state['values']['text_field'];
$query = db_select('table_name', 'n');
$query-&gt;fields('n', array('field_1','field_2','field_3'));
$query-&gt;condition('n.field_0', $text, '=');
$column_name = $query-&gt;execute();
I created two forms and called the second one only after the first form is submitted. To create a table i used table theme.

if (!empty($form_state['values']['text'])) {


 //db_query here to search the key word
 $text = $form_state['values']['text'];
$header=array(t('patient id'), t('patient name'));
$row = array( 
    array(
t('one'),t('two')
    ),
);

 $form['table']=array(
 '#theme'=&gt;'table',
 '#header'=&gt;$header,
 '#rows'=&gt;$row,
 ); 
 }
 else {

 $form['text'] = array(
'#type' =&gt; 'textfield',
'#title' =&gt; t('patient_id'
));

 $form['buttons']['submit'] = array(
'#type' =&gt; 'submit',
'#value' =&gt; t('Submit Button'),
//'#ajax'=&gt; array('callback'=&gt;'anonymous_page'),

); 
}
return $form;
}


in the form submit add 

$form_state['rebuild']=true;