Db_Query Fatal error: Unsupported operand types I am simply trying to return the rows from a table in my db but i keep getting this error thrown back at me no matter what I do "Fatal error: Unsupported operand types in C:\xampp\htdocs\d7\includes\form.inc on line 1009". Am I missing a argument or something?

This is my function

Hook menu

function auto_form_menu() {
$items = array();
$items['admin/config/auto_form'] = array(
    'title' =&gt; 'My Module',
    'description' =&gt; 'description',
    'page callback' =&gt; 'drupal_get_form',
    'page arguments' =&gt; array('auto_form_records'),
    'access arguments' =&gt; array('administer site configuration'),
    'file' =&gt; 'auto_form.admin.inc'
);

$items['admin/config/auto_form/manage'] = array(
    'title' =&gt; 'My Module',
    'type' =&gt; MENU_DEFAULT_LOCAL_TASK,
    'description' =&gt; 'description',
    'weight' =&gt; -10,
);
return $items;
}


'auto_form.admin.inc'

function auto_form_records() {
  $header = array('First Name', 'Last Name');

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

    $rows = array();
    foreach ($dbresult as $dbrow) {
        $rows[] = array(
        $dbrow-&gt;first,
        $dbrow-&gt;last
      );
    }
    return $output = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
}


Updated Code:

Any help is appreciated seeing how I am completely lost on figuring this out.
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.