Someone on the list posted this a while back
it is the easiest method I've seen to alternate
row colors (of course this code is abridged)

<snip>
$colors = array( '#e4e4e4', '#ffffff' );

$i = 0;
//start loop
while (whatever)
{
echo "<tr bgcolor=" . $colors[ $i ++ % count( $colors ) ] . ">";
}
</snip>

Jerry Lake            - [EMAIL PROTECTED]
Web Designer
Europa Communications - http://www.europa.com
Pacifier Online     - http://www.pacifier.com


-----Original Message-----
From: Manuel Lemos [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 08, 2001 10:43 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Row colors


Hello Mike,

On 08-Apr-01 21:08:17, you wrote:

>I can change the column sof a table with the following code but how do I
>change the row colors instead.With the columns I have "i" to manipulate but
>not with rows.

>while ($row = mysql_fetch_row($result))
>{{
>       echo "<TR>\n";
>       for ($i =1;$i<mysql_num_fields($result);$i++)
>               {$cell_color = "#C0C0C0";
>       $i % 2  ? 0: $cell_color = "#CCCCCC";
>       echo "<td bgcolor=\"$cell_color\">$row[$i]</td>";

What you need to do is very simple.  Just echo the <TR> inside your
for loop and make it BGCOLOR attribute change according to the row number.

While you are at it, maybe you would like to try this PHP table listing
class that not only lets you iterate and change colors for each row but it
also lets you change the highlighting color that the row will have when the
mouse is over them.

http://phpclasses.UpperDesign.com/browse.html/package/120


For display database query results, you may want to try this PHP class
based on the previous that is also able to display links to go between any
pages that the results may be split.

http://phpclasses.UpperDesign.com/browse.html/package/130



Regards,
Manuel Lemos

Web Programming Components using PHP Classes.
Look at: http://phpclasses.UpperDesign.com/?[EMAIL PROTECTED]
--
E-mail: [EMAIL PROTECTED]
URL: http://www.mlemos.e-na.net/
PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp
--


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to