<?php $sql = 'SELECT * FROM `table` WHERE `column` = \'something\''; $qry = mysql_query($sql) or die(mysql_error()); // Cell colors for odd rows $c1 = array('#00CCCC', '#33CC00', '#CC0000', '#CCCC00', '#0000CC', '#FF6600', '#CC00CC', '#00CC99'); // Cell Colors for even rows $c2 = array('#66FFFF', '#66FF00', '#FF3300', '#FFFF33', '#0033FF', '#FF9933', '#FF33CC', '#00FF99'); // Row Counter $cnt = 0; $ret = '<table>'; while($row = mysql_fetch_assoc($qry)) { // Cell counter $cnt2 = 0; $ret .= '<tr>'; foreach($row as $key=>$val) { $ret .= '<td bgcolor="'; if($cnt % 2) { $ret .= $c1[$cnt2]; } else { $ret .= $c2[$cnt2]; } $ret .= '">'.$val.'</td>'; ++$cnt2; } ++$cnt; $ret .= '</tr>'."\n"; } $ret .= '</table>'; echo $ret; ?>
You need to create an account or log in to post comments to this site.