diff --git a/batch_example/batch_example.module b/batch_example/batch_example.module index f16509e..9b439f9 100644 --- a/batch_example/batch_example.module +++ b/batch_example/batch_example.module @@ -88,7 +88,7 @@ function batch_example_simple_form_submit($form, &$form_state) { // Reset counter for debug information. $_SESSION['http_request_count'] = 0; - // Execute the function named batch_example_1 or batch_example_2. + // Execute the function named batch_example_batch_1 or batch_example_batch_2. $batch = $function(); batch_set($batch); } diff --git a/dbtng_example/dbtng_example.module b/dbtng_example/dbtng_example.module index f468dc4..07ca903 100644 --- a/dbtng_example/dbtng_example.module +++ b/dbtng_example/dbtng_example.module @@ -1,4 +1,5 @@ TRUE, 'type' => MENU_LOCAL_TASK, ); + $items['examples/dbtng/selectivelist'] = array( + 'title' => 'Selective List', + 'page callback' => 'dbtng_example_selective_list', + 'access callback' => TRUE, + 'type' => MENU_LOCAL_TASK, + 'weight' => -4, + ); return $items; } @@ -574,6 +586,33 @@ function dbtng_example_form_update_submit($form, &$form_state) { drupal_set_message(t("Updated entry @entry (@count row updated)", array('@count' => $count, '@entry' => print_r($entry, TRUE)))); } + +/** + * Select only certain fields from the database + * + * As with any database query we should only bring in the data we need. + * DBTNG gives us the field method that expects the table name followed by an + * array of the fields we want, in this case the table dbtng_example and + * the fields name and age. + * + */ +function dbtng_example_selective_list() { + $output = ''; + // Bring in two fields from the dbtng_example table for the uid 1. + $select = db_select('dbtng_example') + ->fields('dbtng_example', array('name', 'age')) + ->condition('uid', 1) + ->execute(); + $rows = array(); + $header = array(t('Name'), t('Age')); + foreach ($select 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. + } + $output .= theme('table', array('header' => $header, 'rows' => $rows)); + return $output; +} /** * @} End of "defgroup dbtng_example". */