I have what should be a simple question. I am coding a module that allows the user to add meta and link tags to the of your HTML page..think of something similar to CSS injector. (I'm sure something like this already exists, but I'm using this as a learning project). I am able to create the config forms and everything that the admin would need to create a new entry, and I'm able to input new entries and save them to the database.

What I want is below the "new entry" part of the form, I want to list all current entries with "edit" and "delete" links next to each one (every module under the sun has this functionality). Can someone point me in the right direction on how to do this?

| improve this question | | | | |

To expand on mojzis's comment:

// Load your data.
$entries = db_query('SELECT * FROM {my_table}')->fetchAll();

// Prepare a header for your table. The array keys will match up to the key used to input rows in a minute. The values are the column headers.
$header = array(
  'title' => 'Entry title',
  'foo' => 'Bar',
  'op' => 'Operations',

// Loop through your data and prepare table rows.
$rows = array();
foreach ($entries as $entry) {
  // Prepare your operation links.
  $op_links = array(
    l('view', 'path/to/entry/' . $entry->id),
    l('edit', 'path/to/entry/' . $entry->id . '/edit', array('query' => drupal_get_destination())),
    l('delete', 'path/to/entry/' . $entry->id . '/delete', array('query' => drupal_get_destination())),

  $rows[] = array(
    'title' => $entry->title,
    'foo' => $entry->bar,
    'op' => implode(' ', $op_links),

// Prepare the build
$form['existing_entries'] = array(
  '#theme' => 'table',
  '#header' => $header,
  '#rows' => $rows,
  '#empty' => t('No entries have been created.'),
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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