Jump to content

[SOLVED] Switch TR color in a while loop by evens or odds


iceman023

Recommended Posts

I have a table that is in a while loop

 

$numrowsC = mysql_num_rows($newStatement); while ($newData = mysql_fetch_array($newStatement))
{
	echo "<table width='864' border='5' align='center' bgcolor='#F4F4F4' bordercolor='#000000' fontcolor='#000000' cellspacing='5' cellpadding='5'>";
	echo "<tr>";

 

is there anyway i can add a switch within the loop and change the background color of the rows... maybe something like IF odd number from $numrowsC it will be blue and if even it will be red.. something like that...

it didnt work but i may have entered it wrong.. im kinda new to php..

 

 

<?php
while ($newData = mysql_fetch_array($newStatement))
{
$loop = 1;
	echo "<table width='864' border='5' align='center' bgcolor='#F4F4F4' bordercolor='#000000' fontcolor='#000000' cellspacing='5' cellpadding='5'>";
	echo "<tr>";
	echo "<td>";
	echo "<h3>";
	echo "<br />";
	echo "<font size='3' color='ff00d2'>";
	echo "&nbsp &nbsp Commented By: &nbsp &nbsp";
	echo $newData['Author'];
	echo "</font>";
	echo "<ul>";
	echo "<li>";
	echo $newData['Comments']; //the actual text of the comment
	echo "</li>";
	echo "</ul>";
$loop++;
if ($loop % 2) $trcolor = 'blue';
  	else $trcolor = 'red';
?>

yeh u did it wrong lol

 

<?php
   $loop = 1;
     echo "<table width='864' border='5' align='center' bgcolor='#F4F4F4' bordercolor='#000000' fontcolor='#000000' cellspacing='5' cellpadding='5'>";
while ($newData = mysql_fetch_array($newStatement))
   {
    $loop++;
    if ($loop % 2) $trcolor = 'blue';
     else $trcolor = 'red';
      echo "<tr bgcolor='$trcolor'>";
      echo "<td>";
      echo "<h3>";
      echo "<br />";
      echo "<font size='3' color='ff00d2'>";
      echo "&nbsp &nbsp Commented By: &nbsp &nbsp";
      echo $newData['Author'];
      echo "</font>";
      echo "<ul>";
      echo "<li>";
      echo $newData['Comments']; //the actual text of the comment
      echo "</li>";
      echo "</ul>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.