You are here

function dbtng_example_list in Examples for Developers 7

Render a list of entries in the database.

Related topics

1 string reference to 'dbtng_example_list'
dbtng_example_menu in dbtng_example/dbtng_example.module
Implements hook_menu().

File

dbtng_example/dbtng_example.module, line 448
This is an example outlining how a module can make use of the new DBTNG database API in Drupal 7.

Code

function dbtng_example_list() {
  $output = '';

  // Get all entries in the dbtng_example table.
  if ($entries = dbtng_example_entry_load()) {
    $rows = array();
    foreach ($entries as $entry) {

      // Sanitize the data before handing it off to the theme layer.
      $rows[] = array_map('check_plain', (array) $entry);
    }

    // Make a table for them.
    $header = array(
      t('Id'),
      t('uid'),
      t('Name'),
      t('Surname'),
      t('Age'),
    );
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
    ));
  }
  else {
    drupal_set_message(t('No entries have been added yet.'));
  }
  return $output;
}