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, &$form_state) {
$text = $form_state['values']['text_field'];
$query = db_select('table_name', 'n');
$query->fields('n', array('field_1','field_2','field_3'));
$query->condition('n.field_0', $text, '=');
$column_name = $query->execute();
  • Why are you not able to do this with a view and filtering with a search exposed filter? – Justme Aug 26 '16 at 14:45
  • I am able to do that way. I am a beginner, I want to try it this way. – ana Aug 27 '16 at 4:19
  • So far you've started a bunch of facts, but not any question. You should edit your question to ask some thing specific, so readers know what you're looking for. – Shawn Conn Aug 27 '16 at 17:23

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( 

 else {

 $form['text'] = array(
'#type' => 'textfield',
'#title' => t('patient_id'

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

return $form;

in the form submit add

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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