how can I do a listage that has a color for each row, like GREEN -> WHITE -> BLUE -> WHITE -> GREEN ? I always want to have the WHITE between GREEN and BLUE (or other 2 colors) . Any ideas?
Keep a counter and various variables.
If the entry is even then always print white. Else check to see if you're on blue or green.
You can do a mod check to see if a value is odd or even (there might be a builtin function, dunno).
Try this example :
<table> <?php for ($a=0; $a <= 10; $a++) {
// If odd then white else it's grey $bgcolor = $a & 1 ? '#ffffff' : '#eeeeee';
echo '<tr bgcolor="'.$bgcolor.'">'; echo '<td>'.$a.'</td>'; echo '</tr>';
} ?> </table>
I'm new at this and the ternary confuses me:
$a & 1
I'm unfamiliar with the &.
What is
7 & 1
12 & 1
Aren't they all true?
Check out this recent general mailing list post here :
http://marc.theaimsgroup.com/?l=php-general&m=98382848504468&w=2
It will explain it. & is not ternary, it's a bitwise operator. I used ternary just to make the code short and look complex and guruish. Read the above explaination and it'll make more sense!
Thanks.
All these little unorthodox tricks you don't find in books reminds me I've got a lot to learn... 🙂
for ($i=0; $i<$number_of_result; $i++){ .....
if ($i % 2) $colorcell="#ffffff"; //if odd else $colorcell="#eeeeee"; //even ......
}