how to make a page with record displayed from database I am using a cutom module to display records from database.code below fetches all the record from database table but does not know how to display it on a page in my Drupal site (version 7):



function formModule_menu() {
  $items = array();

  $items['form/formModule'] = array( //this creates a URL that will call this form at "examples/form-example"
    'title' =&gt; 'Form', //page title
    'description' =&gt; 'A form with a text field and Submit button.',
    'page callback' =&gt; 'formModule_intro', //this is the function that will be called when the page is accessed.  for a form, use drupal_get_form

    'access callback' =&gt; TRUE,
    'expanded' =&gt; TRUE,
  );

  $items['form/formModule/form1'] = array(
    'title' =&gt; 'Form One',
    'page callback' =&gt; 'drupal_get_form',
    'page arguments' =&gt; array('formModule_form'),
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_NORMAL_ITEM,
    'weight' =&gt; 1,
  );

  $items['form/formModule/reviewOrder'] = array(
    'title' =&gt; 'Review Order',
    'page callback' =&gt; 'formModule_page',
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_NORMAL_ITEM,
    'weight' =&gt; 2,
  );

  return $items;
}


function formModule_page() {
return array('#markup' =&gt; '&lt;p&gt;' . t('Review Order: The table below shows the TOTAL STOCK and TOTAL QUANTITY of product purchased.') . '&lt;/p&gt;');

  $query = db_select('formmodule_order', 't'); // Using the TableSort Extender is what tells the
  $query-&gt;fields('t');
  $result = $query-&gt;execute()-&gt;fetchAll();

 $rows[] = array('data' =&gt; (array) $row);

  foreach ($result as $key =&gt; $row) { 
  $rows[$key] = array(); 

  foreach($row as $col) {
   $rows[$key][] = array('data' =&gt; $col); 

   } 
  }
drupal_set_message("&lt;pre&gt;" . print_r($rows, true) . "&lt;/pre&gt;");

}




iam using the following code to dispaly it on a page but no results:



$header = array(
    // The header gives the table the information it needs in order to make
    // the query calls for ordering. TableSort uses the field information
    // to know what database column to sort by.
    array('data' =&gt; t('S.No.'), 'field' =&gt; 't.S.No.'),
    array('data' =&gt; t('Product Name'), 'field' =&gt; 't.Product Name'),
    array('data' =&gt; t('Total Stock'), 'field' =&gt; 't.Total Stock'),
    array('data' =&gt; t('Total Purchasing'), 'field' =&gt; 't.Total Purchasing'),

  );
 drupal_set_message("&lt;pre&gt;" . print_r($header, true) . "&lt;/pre&gt;");**/
  $query = db_select('formmodule_order', 't'); // Using the TableSort Extender is what tells the

            // the query object that we are sorting.
  $query-&gt;fields('t');

//drupal_set_message("&lt;pre&gt;" . print_r($query, true) . "&lt;/pre&gt;");

 $result = $query-&gt;execute()-&gt;fetchAll();

// drupal_set_message("&lt;pre&gt;" . print_r($result, true) . "&lt;/pre&gt;");

  foreach ($result as $key =&gt; $row) { 
  $rows[$key] = array(); 
   foreach($row as $col) {
   $rows[$key][] = array('data' =&gt; $col); 
   } 
  }
drupal_set_message("&lt;pre&gt;" . print_r($rows, true) . "&lt;/pre&gt;");
  // build the table for the nice output.
  $build['formmodule_order'] = array(
    //'#theme' =&gt; 'table',
    //'#header' =&gt; $header,
    '#rows' =&gt; $rows,
  );

 drupal_set_message("&lt;pre&gt;" . print_r($build, true) . "&lt;/pre&gt;");
  return $build;




what is wrong in the code?
Probably because before anything has a chance to print you are already returning #markup from formModule_page().
You might also want to use the Devel module's dpm() function for more cleaner and convenient debug messages and variable inspection.