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, &$form_state) {
$form['generateList'] = array(
    '#type' => 'item',
    '#description' => 'This is the achievements table',
    '#value' => achievementList_generate_table(),


return $form;


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

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

return $table;

1 Answer 1


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

  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – mpdonadio
    Commented Oct 20, 2014 at 21:52
  • Thanks for pointing that out @MPD, it's sensible guidance. Updating my answer...
    – griz
    Commented Oct 20, 2014 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.