How can I display lots of rows of information from a database in my drupal module? In the example_page I believe it shows something like this:

function foo() {
    return array('#markup' =&gt; t('bar'));
}


And the function foo would be used for a page callback in the menu hook to create a page. However, In my module I plan on using a db_query to access a database table and with it display many rows of data.

Is there a better way to do this than stuffing all of my output into #markup? It could be done with lots of concatenation, but it would be rather messy and it seems like there should be a better way.
If you're looking to build an HTML table then the theme_table() function will help a lot. See the docs page for full details but this is a basic example:

function MYMODULE_page_callback() {
  // Header for the table
  $header = array('id', 'name');

  // Get your data
  $data = db_query('SELECT id, name FROM {my_table}')-&gt;fetchAllKeyed();

  // Loop through the data and add rows to the table
  $rows = array();
  foreach ($data as $id =&gt; $name) {
    $rows[] = array(
      $id,
      $name
    );
  }

  // Return the themed table
  return theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));

  // You could also use:
  return array(
    '#theme' =&gt; 'table',
    '#header' =&gt; $header,
    '#rows' =&gt; $rows
  );
}