Re: Two color rows in table inside while iteration
| From: | Paul M Foster | Date: | Fri, 30 Apr 2010 14:34:15 +0000 |
| Subject: | Re: Two color rows in table inside while iteration | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304776@lists.php.net to get a copy of this message | ||
On Thu, Apr 29, 2010 at 05:34:38PM -0400, tedd wrote:
> At 11:01 AM -0300 4/29/10, Juan Rodriguez Monti wrote:
<snip>
>>
>> Tedd,
>> Thanks. I'm gonna check it. I finally solved it using:
>>
>> if ( CONDITIONS )) {
>>
>> $results = query( QUERY );
>> $colors = array('#97b7cd','#96bf8c');
>> $index= 0;
>> echo "<html>";
>> echo "<head>";
>> echo '<link rel="stylesheet" type="text/css"
>> href="is.css" />';
>> echo "</head>";
>> echo "<body>";
>> echo '<div id="container">';
>>
>> echo "<table border='1'>";
>> echo "<td><strong>a1</strong></td>
>> <td><strong>a2</strong></td>
>> <td><strong>a3</strong></td>
>> <td><strong>a4</strong></td>
>> <td><strong>a5</strong></td> ";
>>
>> while ($row = CONDITIONS )) {
>> echo '<tr style="background-color: ' . $colors[$index ++ %
>> 2] . ';">';
>> echo "<td>$row[0]</td><td>$row[1]</td>
>> <td>$row[2]</td>
>> <td>$row[3]</td><td>$row[4]</td> ";
>> }
>> echo "</tr>";
>> echo "</table>";
>> echo "</div>";
>> echo '<p><a href="back.html">back</a></p>';
>> echo "</body>";
>> echo "</html>";
>>
>> This solution was the best for me. It's solved with your help.
>>
>> Thanks a lot!.
>>
>> Juan
>
> The above is far more complicated than it has to be.
>
> Please critically review my example.
+1
This thread came up before, and tedd's solution was the least complex,
as far as I could tell. I shamelessly stole his code and regularly use
it in my own projects. ;-}
Paul
--
Paul M. Foster