RE: [PHP] Row colors

From: Date: Mon, 09 Apr 2001 16:47:14 +0000
Subject: RE: [PHP] Row colors
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47829@lists.php.net to get a copy of this message
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 - jerryl@europa.com Web Designer Europa Communications - http://www.europa.com Pacifier Online - http://www.pacifier.com -----Original Message----- From: Manuel Lemos [mailto:mlemos@acm.org] Sent: Sunday, April 08, 2001 10:43 PM To: php-general@lists.php.net 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/?user=mlemos@acm.org -- E-mail: mlemos@acm.org 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: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#47829) next »