retrieving values from a database in drupal 7 I am new to drupal. I am trying to create a function that will retrieve rows from a database and display the results.From the tutorials I have read, I am trying to implement a function I have created but no results are displayed. There's just a whitespace. Where might I be going wrong? Here is my code.

function print_users(){
$query = "SELECT first_name, middle_name, last_name FROM {registered_users}";
$header = array(
array('data' =&gt; t('Cell 1'), 'field' =&gt; 'first_name', 'sort' =&gt; 'ASC'),
array('data' =&gt; t('Cell 2'), 'field' =&gt; 'middle_name'),
array('data' =&gt; t('Cell 3'), 'field' =&gt; 'last_name'),
);
$q = db_query($query . tablesort_sql($header));
while ($r = db_fetch_array($q)) {
    $rows[] = $r;
}
print theme('table', $header, $rows);


}

and am calling it as follows via a menu link

 $items['view_users'] = array(
        'title' =&gt; "view",
        'description' =&gt; 'Viewing service',
        'page callback' =&gt; "print_users",
        'access callback' =&gt; TRUE, 
        'weight' =&gt; '2',


);
$select = db_select('registered_users', 'c')
-&gt;condition('c.fieldname', $id)  //try the condition if u have anything
-&gt;fields('c');

$result = $select-&gt;execute();
if($result-&gt;rowCount() == 0) return false;

$val = $result-&gt;fetch();


for sorting try asc or desc followed by the condition
you can get the answer in google itself