Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bios site help......

Status
Not open for further replies.

aldumil

Programmer
Sep 3, 2001
40
JP
I am making a a dealio for friends to post their bios on a site using XML and PHP. I want to display their names in a table and:::heres the part I need help on:::: I want the rows in the table to alternate between white background and maroon background. I came up with something like.......

$i = 0;
for(generate table expression thingy){
if($i) { print &quot;<tr><td bgcolor=#000000>foo</td></tr>\n&quot;; else print &quot;<tr><td bgcolor=#ffffff>foo</td></tr>\n&quot;;
}

but I can't seem to make it work. ideas??
 
use the modulus operator on the number 2 to check for even and uneven numbers. everytime there's an even number print black and when it's uneven print white.
example:
Code:
for($i = 0; $i <= $number_of_fields; $i++){
	$td_color = $i % 2 ? &quot;000000&quot; : &quot;FFFFFF&quot;;
	print &quot;<tr><td bgcolor=\&quot;#$td_color\&quot;>foo</td></tr>\n&quot;;
}

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top