Display the results of a form submit on the same page just under the form I have created a form and it takes in 3 values which are Brand, Item and Zipcode. The values are queried and the results are fetched the database table. I want the results to be shown in a table

function form_example_form_submit($form, &amp;$form_state) {
$sql3 = /*my select query*/

$result = db_query($sql3);
$records = $result-&gt;fetchAll();

//code to display table

 echo "&lt;table border=1&gt;";
   echo"&lt;tr&gt;";
    echo"&lt;th&gt;Retail Accounts&lt;/th&gt;";
    echo"&lt;th&gt;Address&lt;/th&gt;";
    echo"&lt;th&gt;City&lt;/th&gt;";
    echo"&lt;th&gt;State&lt;/th&gt;";
   echo "&lt;/tr&gt;";
   foreach ($records as $record) {
    $record     = get_object_vars($record);
    echo "&lt;tr&gt;";
      echo "&lt;td&gt;";
        echo $record['Retail Accounts'];
      echo "&lt;/td&gt;";
      echo "&lt;td&gt;";
        echo $record['ADDR'];
      echo "&lt;/td&gt;";
      echo "&lt;td&gt;";
        echo $record['CITY'];
      echo "&lt;/td&gt;";
      echo "&lt;td&gt;";
        echo $record['STATE'];
      echo "&lt;/td&gt;";
    echo"&lt;/tr&gt;";    
}
echo "&lt;/table&gt;";
}


The result is properly fetched but not displayed on the page.

I tried $form_state['rebuild'] = TRUE; but it displays the result on top of the page.

I want the result to be visible just below my form. How can I achieve that?

Any help is very much appreciated. Thanks in advance.
As suggested in the comment the SQl query were made on the hook_form and the hook_form_submit contains only the $form_state['rebuild'] = TRUE;. Detailed code is as follows:

function form_example_form($form, &amp;$form_state) {

//your form fields or items

$form['submit_button'] = array(
 '#type' =&gt; 'submit',
 '#prefix' =&gt; '&lt;div class="button-wrapper"&gt;',
 '#suffix' =&gt; '&lt;/div&gt;',
 '#value' =&gt; t('Find my store'),
 '#attributes' =&gt; array('class' =&gt; array('btn btn-primary')),
);


/*-----Query database code Start--------*/

if(isset($form_state['values']['item-name'])){
  //get the values to variable
}

if(isset($zip_code)){


//setup the sql query


if(isset($sql3)){
  $result = db_query($sql3);
}
$records = $result-&gt;fetchAll();
$tot_records = count($records);
}

if(isset($tot_records)){
 if($tot_records&gt;0){ 

  $form['result_table'] = array(
    '#type' =&gt; 'markup',
    '#prefix' =&gt; '&lt;table border=0 class="table table-bordered"&gt;',
    '#markup' =&gt; '&lt;tr&gt;&lt;th&gt;Store Name&lt;/th&gt;&lt;th&gt;Address&lt;/th&gt;&lt;th&gt;City&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;/tr&gt;',
  );

  $i=0; $j=0;  
  foreach ($records as $record) {

    $record_in_array = json_decode(json_encode($records[$i]), true); //Convert object to array

    $form[$j]['result_table1']= array(
      '#type' =&gt; 'markup',
      '#markup' =&gt; '&lt;tr&gt;',
    );      

    $form[$j]['result_table2']= array(
      '#type' =&gt; 'markup',
      '#prefix' =&gt; '&lt;td&gt;',
      '#suffix' =&gt; '&lt;/td&gt;',
      '#markup' =&gt; $record_in_array['sql column name1'],
    );
    $form[$j]['result_table3']= array(
      '#type' =&gt; 'markup',
      '#prefix' =&gt; '&lt;td&gt;',
      '#suffix' =&gt; '&lt;/td&gt;',
      '#markup' =&gt; $record_in_array['sql column name2'],
    );
    $form[$j]['result_table4']= array(
      '#type' =&gt; 'markup',
      '#prefix' =&gt; '&lt;td&gt;',
      '#suffix' =&gt; '&lt;/td&gt;',
      '#markup' =&gt; $record_in_array['sql column name3'],
    );
    $form[$j]['result_table5']= array(
      '#type' =&gt; 'markup',
      '#prefix' =&gt; '&lt;td&gt;',
      '#suffix' =&gt; '&lt;/td&gt;',
      '#markup' =&gt; $record_in_array['sql column name4'],
    );


    $form[$j]['result_table6']= array(
      '#type' =&gt; 'markup',
      '#markup' =&gt; '&lt;/tr&gt;',
    );

    $i++;
    $j++;
  }

  $form['result_table7']= array(
    '#type' =&gt; 'markup',
    '#suffix' =&gt; '&lt;/table&gt;',
  );

  }      
 }

/*-----End Query database code--------*/

return $form;

 }

 function form_example_form_submit($form, &amp;$form_state) {
  $form_state['rebuild'] = TRUE;
 }


Hope this helps!