Skip to content

Instantly share code, notes, and snippets.

@rintoug
Created March 25, 2017 08:35
Show Gist options
  • Save rintoug/8d895c7a780c904beb0479afcf079d31 to your computer and use it in GitHub Desktop.
Save rintoug/8d895c7a780c904beb0479afcf079d31 to your computer and use it in GitHub Desktop.
Custom sql query & display it in a table in drupal
<?php
$sql = 'SELECT name, email, mobile, place FROM {test}';
$header = array(
array('data' => 'name', 'field' => 'name'),
array('data' => 'email', 'field' => 'email'),
array('data' => 'mobile', 'field' => 'mobile'),
array('data' => 'place', 'field' => 'place'),
);
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);
while ($data = db_fetch_object($result)) {
$rows[] = array($data->name, $data->email, $data->mobile, $data->place);
}
if (!$rows) {
$rows[] = array(array('data' => t('Empty -n results'), 'colspan' => '4'));
}
echo theme('table', $header, $rows);
echo theme('pager', NULL, 50, 0);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment