From: Juan Rodriguez Monti on
2010/4/29 tedd <tedd.sperling(a)gmail.com>:
> At 8:29 AM -0300 4/28/10, Juan Rodriguez Monti wrote:
>>
>> Hello Guys,
>> I would like to implement a two color row table for some queries that I'm
>> doing.
>>
>> I use PHP to query a DB, then I use while to print all its results. I
>> have a code pretty similar to this one :
>>
>>  $results = Here the QUERY;
>>        echo "<html>";
>>        echo "<head>";
>>        echo '<link rel="stylesheet" type="text/css" href="style.css" />';
>>        echo "</head>";
>>        echo "<body>";
>>        echo '<div id="container">';
>>
>>        echo "<center><h2>Results</h2></center><br />";
>>        echo ("<table border='1'>");
>>        echo "<td><strong>At1</strong></td>
>> <td><strong>At2</strong></td> <td><strong>At3</strong></td>      $
>>
>>  while ($row = while condition )) {
>>        echo ("<tr>");
>>        echo "<td>$row[0]</td><td>$row[1]</td> <td>$row[2]</td>
>> <td>$row[3]</td><td>$row[4]</td> ";
>>        echo "</div>";
>>        echo "</body>";
>>        echo "</html>";
>>
>> I just want to show you how I write the table. What I would like to
>> know is what do you suggest to do a two color row format.
>>
>> Thanks!,
>> Juan
>
>
> Juan:
>
> Everyone has done this at one time or another -- this is my solution.
>
> http://webbytedd.com/b/color-rows/
>
> Plus, it validates and keeps things simple.
>
> Cheers,
>
> tedd

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
From: Al on


On 4/28/2010 7:29 AM, Juan Rodriguez Monti wrote:
> Hello Guys,
> I would like to implement a two color row table for some queries that I'm doing.
>
> I use PHP to query a DB, then I use while to print all its results. I
> have a code pretty similar to this one :
>
> $results = Here the QUERY;
> echo "<html>";
> echo "<head>";
> echo '<link rel="stylesheet" type="text/css" href="style.css" />';
> echo "</head>";
> echo "<body>";
> echo '<div id="container">';
>
> echo "<center><h2>Results</h2></center><br />";
> echo ("<table border='1'>");
> echo "<td><strong>At1</strong></td>
> <td><strong>At2</strong></td> <td><strong>At3</strong></td> $
>
> while ($row = while condition )) {
> echo ("<tr>");
> echo "<td>$row[0]</td><td>$row[1]</td> <td>$row[2]</td>
> <td>$row[3]</td><td>$row[4]</td> ";
> echo "</div>";
> echo "</body>";
> echo "</html>";
>
> I just want to show you how I write the table. What I would like to
> know is what do you suggest to do a two color row format.
>
> Thanks!,
> Juan

$str= "<table>";

$alt = 'even';

foreach(...){
$alt = ($alt == 'odd')?'even':'odd';
$str .= "<tr class=\"$alt\"><td>foo</td></tr>"; // Populate each row;
}

$str .= "</table>\n";

echo $str;

From: tedd on
At 11:01 AM -0300 4/29/10, Juan Rodriguez Monti wrote:
>2010/4/29 tedd <tedd.sperling(a)gmail.com>:
>> At 8:29 AM -0300 4/28/10, Juan Rodriguez Monti wrote:
>>>
>>> Hello Guys,
>>> I would like to implement a two color row table for some queries that I'm
>>> doing.
>>>
>>> I use PHP to query a DB, then I use while to print all its results. I
>>> have a code pretty similar to this one :
>>>
>>> $results = Here the QUERY;
>>> echo "<html>";
>>> echo "<head>";
>>> echo '<link rel="stylesheet" type="text/css" href="style.css" />';
>>> echo "</head>";
>>> echo "<body>";
>>> echo '<div id="container">';
>>>
>>> echo "<center><h2>Results</h2></center><br />";
>>> echo ("<table border='1'>");
>>> echo "<td><strong>At1</strong></td>
>>> <td><strong>At2</strong></td> <td><strong>At3</strong></td> $
>>>
>>> while ($row = while condition )) {
>>> echo ("<tr>");
>>> echo "<td>$row[0]</td><td>$row[1]</td> <td>$row[2]</td>
>>> <td>$row[3]</td><td>$row[4]</td> ";
>>> echo "</div>";
>>> echo "</body>";
>>> echo "</html>";
>>>
>>> I just want to show you how I write the table. What I would like to
>>> know is what do you suggest to do a two color row format.
>>>
>>> Thanks!,
>>> Juan
>>
>>
>> Juan:
>>
>> Everyone has done this at one time or another -- this is my solution.
>>
>> http://webbytedd.com/b/color-rows/
>>
>> Plus, it validates and keeps things simple.
>>
>> Cheers,
>>
>> tedd
>
>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.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
From: shiplu on
$a=0;
while (++$a, $row=mysql_fetch_...){
echo "<tr class=‌‌‌‌‌‌\"alternate-row-".($a%2)."\"><..."
}


Shiplu Mokaddim
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
SUST Programmers, http://groups.google.com/group/p2psust
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)
From: "Daevid Vincent" on
> -----Original Message-----
> while(foo){
> $tr = (0 == $trColor % 2)? "#E8E8E8" : "#FFFFFF";
> echo "<tr style=\"background-color:".$tr."\">";
> ...

Don't do this modulus (%) math!!!! Just toggle a boolean!!

<tr class="<?= ($r = !$r) ? "dataRow1" : "dataRow2"; ?>">