web_master Posted September 28, 2007 Share Posted September 28, 2007 hy, how can I make a 2 color row when I list something from dbase? example: When I listing from dbase with "while", I can't do this. Thanx in advanced. web_m Quote Link to comment Share on other sites More sharing options...
Guardian-Mage Posted September 28, 2007 Share Posted September 28, 2007 sure you can. Use a variable, $x. <?php //All of your code here except the while $x = 0; while (//Stuff Here) { //More of your code here echo "<tr class=\"row" . $x . "\"><td>$content</td></tr>"; if ($x == 0) $x++; else $x--; } ?> Then you need two styles, one for tr.row0 and one for tr.row1 Quote Link to comment Share on other sites More sharing options...
web_master Posted September 28, 2007 Author Share Posted September 28, 2007 Great, its work! THANKS!!!!! Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 28, 2007 Share Posted September 28, 2007 if you're creating the list in a foreach, while or for statement it's quite easy. Before the statement set a variable to 1, then each loop through the statement change the digit to 2, or if it's already 2, back to 1 again. Then set up two css classes, called something like 'line1' and 'line2'. You can then call up the class in php. <?php $i = 1 foreach($var as $k => $v){ echo '<td class="line' . $i . '">some txt</td>'; if($i = 1){ $i = 2; }else{ $i = 1; } } EDIT: beaten to it Quote Link to comment Share on other sites More sharing options...
Guardian-Mage Posted October 5, 2007 Share Posted October 5, 2007 Glad I could help Quote Link to comment 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.