I am fetching records from a custom table and want to display it in a table. Here is my custom table structure:
nid | sku | orderIn | orderOut
1 | prod-1 | 200 | 20
2 | prod-1 | 230 | 10
3 | prod-1 | 250 | 20
4 | prod-1 | 200 | 20
Here is the function where I am using my query to fetch the records from the database. The problem is that drupal_set_message()
doesn't print the array.
function formModule_menu() {
$items = array();
$items['form/formModule/reviewOrder'] = array(
'title' => 'Review Order',
'page callback' => 'formModule_page',
'access arguments' => array('access simple page'),
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
'weight' => 3,
);
return $items;
}
function formModule_page() {
return array('#markup' => '<p>' . t('Review Order: The table below shows the TOTAL STOCK and TOTAL QUANTITY of product purchased.') . '</p>');
// We are going to output the results in a table with a nice header.
$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' => t('S.No.'), 'field' => 't.S.No.'),
array('data' => t('Product Name'), 'field' => 't.Product Name'),
array('data' => t('Total Stock'), 'field' => 't.Total Stock'),
array('data' => t('Total Purchasing'), 'field' => 't.Total Purchasing'),
);
$query = db_select('formmodule_order', 't'); // Using the TableSort Extender is what tells the
// the query object that we are sorting.
$query->fields('t');
$result = $query
->orderByHeader($header) // Don't forget to tell the query object how to
// find the header information.
->execute();
$rows = array();
foreach ($result as $row) {
// normally we would add some nice formatting to our rows
// but for our purpose we are simply going to add our row
// to the array.
$rows[] = array('data' => (array) $row);
}
// build the table for the nice output.
$build['formmodule_order'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
return $build;
}