Add 'attributes' to an html element In my drupal 7 module which is separate from the node portion of drupal (discrete tables) I'm trying to use the array of 'attributes' to one  element of table using theme().

Here's a simple example:

$query = "SELECT projectID, title, housestaff_needed FROM Projects";
$result = db_query($query)-&gt;fetchAll();
$header = array('name' =&gt; t('Name'), 'title' =&gt; t('Title'), 'housestaff_needed' =&gt; t('Housestaff Needed'));

    foreach ($result as $item) {
      $rows[] = array(
          $item-&gt;title, 
          $item-&gt;housestaff_needed, 
          array('attributes' =&gt; array('id' =&gt; array('staff-' . $item-&gt;projectID))),
          );
    }
    $theme = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
    return $theme;


As you know, this only adds another  element after the housestaff_needed data. I've used this syntax before to enclose an entire table with an attribute, but I've read and read to see how this can be done on just an element but all I've read is how you can do it in the form api using '#attribute' which doesn't seem to be the same thing and a different setup outside the forms.

I'm trying to get this so I can identify this element for a jQuery scripted and can't get to first base. Please point out what I'm not doing correctly, thx, sam
I believe you need to add the data as an array to an associative array with the 'data' key, and the attributes with the attribute name as the key. For instance, your code would look like:

$rows = array();
foreach ($result as $item) {
  $rows[] = array(
    'data' =&gt; array($item-&gt;title, $item-&gt;housestaff_needed),
    'id' =&gt; 'staff-' . $item-&gt;projectID,
  );
}
$theme = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
return $theme;


I think this will add an id to each &lt;tr&gt;. If you want to add attributes to each individual &lt;td&gt;, you would use a similar structure for $item-&gt;title and $item-&gt;housestaff_needed. That is, it would become:

$rows = array();
foreach ($result as $item) {
  $rows[] = array(
    'data' =&gt; array(
      array(
        'data' =&gt; $item-&gt;title,
        'id' =&gt; 'SOME_ID',
      ),
      array(
        'data' =&gt; $item-&gt;housestaff_needed,
        'id' =&gt; 'SOME_OTHER_ID'
      ),
    ),
    'id' =&gt; 'staff-' . $item-&gt;projectID,
  );
}
$theme = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
return $theme;


At least, that's how it works in d6, I beleive, so here's hoping it still works in d7.