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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Routine to change Back Ground Color on each row os a table

Status
Not open for further replies.

SundancerKid

Programmer
Joined
Oct 13, 2002
Messages
116
Location
US
Code:
[COLOR=red] <tr bgcolor="<? if(bcmod($w_i,2)){echo "[/color][COLOR=#666666]grey[/color][COLOR=red]";}else {echo "[/color][COLOR=#0099ff]blue[/color][COLOR=red]";}?>"> [/color]

$w_i is the index I am using to determine what row I am on. 2 is a constant. BCMOD(x,y) will divide x by y. if it is divisable by 2 with no remainder then it is true and the color for the row would be grey, if there is a remainder then it is false then the color would be light blue.

builtin function -> BCMOD(index, value)


Red is the program
Grey is the True(Even Row) color
Light Blue is the False (Odd Row) color
Green are my comments
 
Just keep in mind that not all PHP installations have the BCMath extensions available. But you don't need bcmod(), because PHP provides an intrinsic modulo operator: "%"

Code:
print '<tr bgcolor="';
if($w_i % 2 == 0)
{
   echo "grey";
}
else
{
   echo "blue";
}

print '">';

(Context-switching and inline function calls inside HTML output reduce readability.)

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top