Grouped odd even in table loop

This is how you can override Drupal 6 theme table using odd/even and let theme('table'...) group table rows by an ID (in this case by 'nid') and apply odd and even on the groups.

<?php

$last_nid
= 0;
    foreach (
$status as $key =--> $m) {
       
 
      if(
$last_nid != $m['nid']){
         
$r++;
      }
     
     
$last_nid = $m['nid'];
     
      if (
$r % 2) {
         
$oddeven = "odd-grp";
      } else {
         
$oddeven = "even-grp";
      }

     
$status_out[] = array('data' =&gt; array(l($m['nid'], 'node/'.$m['nid']),
                             
$m['mid'],
                             
$m['level'],
                             
$m['status'],
                             
$m['nbr']),
                             
'class' =&gt; $oddeven);
    }

       
$tableHeaders = array('nid', 'mid', 'Level', 'Status', 'Nbr');
   
$out .= "<h3>" . t('Exisitng working queue status') . "</h3>";
   
$out .= theme('table', $tableHeaders, $status_out);

?>
CSS
<?php
table tr
.odd-grp {
   
background-color: #eef3f1;
}

table tr.even-grp {
   
background-color: #ffffff;
}
?>
Knowledge keywords: