How to display select query results using ajax in a form in drupal7
Without specifics it's tricky to answer your question but here's a very basic example:

function MYMODULE_some_form($form, &amp;$form_state) {
  $form['select'] = array(
    '#title' =&gt; 'Option',
    '#type' =&gt; 'select',
    '#options' =&gt; drupal_map_assoc(array(1,2,3)),
    '#ajax' =&gt; array(
      'wrapper' =&gt; 'some-form-results-wrapper',
      'callback' =&gt; 'MYMODULE_some_form_ajax'
    )
  );

  $form['results'] = array(
    '#prefix' =&gt; '&lt;div id="some-form-results-wrapper"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;'
  );

  // If the form has been submitted, build up your results and display them
  if (isset($form_state['values']['select'])) {
    $rows = db_select('some_table', 't')
      -&gt;fields('t')
      -&gt;condition('some_field', $form_state['values']['select'])
      -&gt;execute()
      -&gt;fetchAll();

    $header = array();

    $form['results']['#markup'] = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
  }
  else {
    $form['results']['#markup'] = '&lt;p&gt;The results will appear here when you change the dropdown option.&lt;/p&gt;';
  }

  return $form;
}

function MYMODULE_some_form_ajax($form, &amp;$form_state) {
  return $form['results'];
}


You might want to check out the ajax_example module included as part of the Examples module, it has a lot of code and comments that will help you understand what every piece of the above example does.