How do you render a table within a custom module in drupal? I have a page on my Drupal module that is responsible for the input of goals to be completed by an admin. What I would like to happen is have all of the goals within the database table render below the input form. However the only thing that gets outputted is the description tag. Using the DBA module I can plainly see a populated achievements table so I assume that the code to call and render the table must be wrong. Does anyone see where I went wrong?

I have the following code...

function achievementList_form($form, &amp;$form_state) {
$form['generateList'] = array(
    '#type' =&gt; 'item',
    '#description' =&gt; 'This is the achievements table',
    '#value' =&gt; achievementList_generate_table(),

);


return $form;
}


and

function achievementList_generate_table() {
$query = db_query('SELECT * FROM {achievements}');

$table = array(
    '#theme' =&gt; 'table',
    '#header' =&gt; array('NID', 'Name', 'Description', 'Points'),
    '#rows' =&gt; array(),
);
foreach($query as $row) {
    $table['#rows'][] = array($row-&gt;achvmntID, $row-&gt;achvmntName, $row-&gt;achvmntDesc, $row-&gt;achvmntPts);
}

return $table;
}
Here's a tutorial which should answer your question:
https://www.drupal.org/node/156863

It's difficult to say much about the way you're querying the database without knowing more about how your data is stored. I will say that you might benefit from defining an Entity type for your achievements.

When it comes to rendering the table you should be returning the output of the 'theme' function, passing 'table' as the first arg, then the header and rows as the second and third:

return theme('table', $header, $rows);


The API page for your version of Drupal will tell you how to structure those variables:
https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7