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

alternate table colors (like here - purple & white) 1

Status
Not open for further replies.

martinb7

Programmer
Joined
Jan 5, 2003
Messages
235
Location
GB
Hi, i was wondereing how you would make a simple alternating td bgcolor

e.g.

purple
white
purple
white

in my forum im trying to change the font color:

here's what i have so far!


Code:
if ($color = "#00ff00")
{
	$color = "#FFFFFF";
}
else
{
	$color = "00FF00";
}
  
  echo(&quot;<font color=$color><b>User</b> $sub replyed to this message on the <b>$dp</b><br><br>$rep</font>&quot;).&quot;<br><br><hr>&quot;;


could someone gve me the code pls??

Thanx

Martin

PS to see what im trying to do visit:

 
Martin,

I am assuming that you are in some sort of loop when you are outputting this information. What you need to use is the modulas (mod) function which is a % in php.

$currentrow =0;
while ($row=mysql_fetch_array()) {
$currentrow++;
if ($currentrow % 2 == 0) {
$color = &quot;#FFFFFF&quot;;
} else {
$color = &quot;#00FF00&quot;;
}
echo(&quot;<font color=$color><b>User</b> $sub replyed to this message on the <b>$dp</b><br><br>$rep</font>&quot;).&quot;<br><br><hr>&quot;;
}

Hope this helps!

Tony
 
That'll change the font color, it's the PHP portion for what you need... but just as a pointer, here's some CSS that will change the backgrounds for you...

What I do for that effect is use a loop like the one provided, but instead of $color=&quot;#FFFFFF&quot; and $color=&quot;#00FF00&quot; I'd say, $class = &quot;light&quot;, $class=&quot;dark&quot; then do
Code:
echo '<td class=&quot;'.$color.'&quot;>;
echo $whateverinformation
echo '</td>';

Then in my css sheet I'd have
td.light {
background-color: #FFFFFF;
}
td.dark {
background-color: #000000;
}
Hope that helps.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top