How to display fetched data in the form of html table? I have created a custom module &amp; used below code to display data from Database. But I want to show that data in the form of html table. Please help.

&lt;?php
function custom_table_menu(){
 $items = array();
 $items['custom_table'] = array(
  'title' =&gt; 'Custom Table',
  'page callback' =&gt; 'custom_table_page_display',
  'access callback' =&gt; TRUE,
);
 return $items;
}


function custom_table_page_display() {
$result = db_query('SELECT * FROM {users}');
  $records = $result-&gt;fetchAll();

  $content = '&lt;pre&gt;' . print_r($records, TRUE) . '&lt;/pre&gt;';

  return $content;
}
?&gt;
Try this example to output your data in table format with Pager (ie. table with page. 1,2,3.. )

function custom_table_page_display() {

  $header = array(
    array('data' =&gt; t('Name'), 'field' =&gt; 'id', 'sort' =&gt; 'desc'),
    array('data' =&gt; t('Address'), 'colspan' =&gt; 3),
  );

  $query = db_select('users', 'u');

  $query-&gt;fields('u', array('name','address'));  // select your required fields here

  $table_sort = $query-&gt;extend('TableSort') // Add table sort extender.

                      -&gt;orderByHeader($header); // Add order by headers.

  $pager = $table_sort-&gt;extend('PagerDefault')

                      -&gt;limit(20);  // here you can limit the number of data per page.

  $result = $pager-&gt;execute();

  $rows = array();
  foreach($result as $res) {
    $rows[] = array($res-&gt;id, 
                    $res-&gt; title,);
  }
  // If rows are not empty theme and display the rows.

  $output = '';

  if (!empty($rows)) {

    $output = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows, 'attributes' =&gt; array('id' =&gt; 'sort-table')));

    $output .= theme('pager');

  }

  else {

    $output .= t("No results found.");

  }

  return $output;

}