Db_Query Fatal error: Unsupported operand types
I'm not sure exactly which one is causing the error but there are a couple of things:


You're trying to loop over a variable called $dbresult which you haven't declared; you probably meant 

$dbresult = db_query("SELECT first, last FROM {autoform}");

$results = '';
foreach ($dbresult as $dbrow) {

It looks like you're using Drupal 7, and the call you're making to theme_table contains arguments in the style of the Drupal 6 call. Variables are all named in Drupal 7 so you need to invoke the function like this:

$output = theme('table', array('header' =&gt; $header, 'rows' =&gt; $data));

theme_table() takes an array of rows, and each of those arrays will have the data for a number of columns, one for each that you've defined in your header. At the moment you're concatenating a single string and creating a single row containing one cell, with that single string in it.

I think something like this is more what you're after:

$rows = array();
foreach ($dbresult as $dbrow) {
  $rows[] = array(
    $dbrow-&gt;first,
    $dbrow-&gt;last
  );
}

$output = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));



Also if you want a nice little shortcut leveraging some of the db API you could use this reduced code:

$header = array('first' =&gt; 'First Name', 'last' =&gt; 'Last Name');
$rows = db_query("SELECT first, last FROM {autoform}")-&gt;fetchAllAssoc();
$output = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));


That last snippet will become less useful the more you need to customise the individual rows/cells of the table.