Re: Re: Alternet row colors
| From: | Chris Hayes | Date: | Mon, 17 Nov 2003 11:44:32 +0000 |
| Subject: | Re: Re: Alternet row colors | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-169919@lists.php.net to get a copy of this message | ||
At 01:28 16-11-03, you wrote:
It's so much easier to use the mod (%) operator: Ah, the alternating rowcolors.I have a proposal that's a lot lighter on your server. I prefer this as it does not require a calculation for each row (%2), and no counter (and no numrows call). I think it will be noticably faster with longer result sets. And your code is shorter. $rowcolor=FALSE; //initialise echo '<table>'; while(...walk trough resultset...) { echo '<tr bgcolor="'
.($rowcolor?'#FF0000':'#00ffff')
.'" ><td>'.$somevalue.' </td></tr>';
$rowcolor=!$rowcolor; //toggles true/false and hence the row color
}
echo '</table>';