Posted by Jochem Maas on 03/30/05 19:17
Georg wrote:
> Hi!
>
> I wish to format the output of a database select.
> The result is presented in a table, in which i'd like to present everey
> secound row with a different background color.
> My idea was to test if the remaining number of rows where a prime number or
modulo 2 .... is the current row 'number' divisible by 2 with no remainder?
(i.e. is it an odd row or an even row)
hint code:
$i = 1;
// assume $rows is your DB resultset
foreach($rows as $row) {
$bgcolor = ($i % 2) ? '#fff': '#f00';
$i++;
$yourColumns = '';
foreach ($row as $field) {
$yourColumns =. "<td>$field</td>";
}
echo '<tr style="'.$bgcolor.'">',$yourColumns,'<tr>';
}
I really think that prime numbers are not what your looking for....
but maybe you have very specific formatting requirements?!!??
> not, and by that determent if the background color should be white or som
> ivory-like color to improve the readability in the result table...
>
> Hope to hear from anyone with experience in similar matters...
btw there are quite a few javascript libs that do auto coloring of HTML tables
in the way you describe - they are pretty much drag'n'drop scripts - I'll
leave finding them up to you ;-)
>
> TIA! Georg Herland, Norway
>
[Back to original message]
|