Perhaps I don't understand what you want, but won't wouldn't something such as this work?
function Generate_Table($DataSet) {
$Fields = mysql_num_fields($DataSet); // Number of fields
echo "\n\n<table> \n";
$BG = '#F8F8EB'; // set the initial tr backgroud color
echo "<tr>";
for ($i = 0; $i < $Fields; $i++) {
echo "<th>",mysql_field_name ($DataSet, $i),"</th>";
}
echo "</tr>\n\n";
while($Row = mysql_fetch_assoc ($DataSet)) {
$BG = ($BG=='#F8F8EB' ? '#F0F0EB' : '#F8F8EB');
echo '<tr style="background: '.$BG.';">';
foreach($Row as $CellData){
echo "<td>$CellData</td>";
}
echo "</tr>\n";
}
echo "</table> \n\n";
}
// Connect to you DB and write you query. Then ...
$Result = mysql_query($Query) ;
Generate_Table ($Result) ;