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 Link to comment https://forums.phpfreaks.com/topic/71020-solved-2-color-rows-when-list/ 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 Link to comment https://forums.phpfreaks.com/topic/71020-solved-2-color-rows-when-list/#findComment-357093 Share on other sites More sharing options...
web_master Posted September 28, 2007 Author Share Posted September 28, 2007 Great, its work! THANKS!!!!! Link to comment https://forums.phpfreaks.com/topic/71020-solved-2-color-rows-when-list/#findComment-357099 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 Link to comment https://forums.phpfreaks.com/topic/71020-solved-2-color-rows-when-list/#findComment-357101 Share on other sites More sharing options...
Guardian-Mage Posted October 5, 2007 Share Posted October 5, 2007 Glad I could help Link to comment https://forums.phpfreaks.com/topic/71020-solved-2-color-rows-when-list/#findComment-362327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.