Created
March 25, 2017 08:35
-
-
Save rintoug/8d895c7a780c904beb0479afcf079d31 to your computer and use it in GitHub Desktop.
Custom sql query & display it in a table in drupal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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