iceman023 Posted May 5, 2009 Share Posted May 5, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/156886-solved-switch-tr-color-in-a-while-loop-by-evens-or-odds/ Share on other sites More sharing options...
RussellReal Posted May 5, 2009 Share Posted May 5, 2009 try sumfin like this: <?php $loop = 1; while (your condition) { $loop++; if ($loop % 2) $trcolor = 'blue'; else $trcolor = 'red'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156886-solved-switch-tr-color-in-a-while-loop-by-evens-or-odds/#findComment-826451 Share on other sites More sharing options...
iceman023 Posted May 5, 2009 Author Share Posted May 5, 2009 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 "    Commented By:    "; 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'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/156886-solved-switch-tr-color-in-a-while-loop-by-evens-or-odds/#findComment-826454 Share on other sites More sharing options...
RussellReal Posted May 5, 2009 Share Posted May 5, 2009 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 "    Commented By:    "; echo $newData['Author']; echo "</font>"; echo "<ul>"; echo "<li>"; echo $newData['Comments']; //the actual text of the comment echo "</li>"; echo "</ul>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/156886-solved-switch-tr-color-in-a-while-loop-by-evens-or-odds/#findComment-826458 Share on other sites More sharing options...
iceman023 Posted May 5, 2009 Author Share Posted May 5, 2009 Thank you Very much!!! Quote Link to comment https://forums.phpfreaks.com/topic/156886-solved-switch-tr-color-in-a-while-loop-by-evens-or-odds/#findComment-826461 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.