Zergman Posted July 26, 2008 Share Posted July 26, 2008 So I have it working using this <?php $count++; if(($count % 2) == 1){ $background = "#CCCCCC"; } else { $background = "#FFFFFF"; } ?> Then in my tr tag <tr bgcolor="<?php echo $background; ?>"> Works great, except I want the colors to be defined in my stylesheet, not on the page itself so my users can change themes and have the row colors change too. I found a tutorial here http://lorenzod8n.wordpress.com/2007/06/02/alternating-row-color-in-htmlcss-with-php/ but I can't seem to get it to work with a database query. Suggestions? Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/ Share on other sites More sharing options...
teng84 Posted July 26, 2008 Share Posted July 26, 2008 So I have it working using this <?php $count++; if(($count % 2) == 1){ $background = "#CCCCCC"; } else { $background = "#FFFFFF"; } ?> Then in my tr tag <tr bgcolor="<?php echo $background; ?>"> Works great, except I want the colors to be defined in my stylesheet, not on the page itself so my users can change themes and have the row colors change too. I found a tutorial here http://lorenzod8n.wordpress.com/2007/06/02/alternating-row-color-in-htmlcss-with-php/ but I can't seem to get it to work with a database query. Suggestions? use classes of css eg .. <?php $count++; if(($count % 2) == 1){ $class = "style1"; } else { $class = "style2"; } ?> <tr class="<?=$class ?>"> Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/#findComment-600009 Share on other sites More sharing options...
samshel Posted July 26, 2008 Share Posted July 26, 2008 you define two classes in your style sheet oddRow evenRow and use like this.. if($i % 2 == 0 ) $class = "oddRow"; else $class = "evenRow"; <tr class="<?php echo $class; ?>"> Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/#findComment-600010 Share on other sites More sharing options...
Zergman Posted July 26, 2008 Author Share Posted July 26, 2008 You guys rock! Works like a freakin charm Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/#findComment-600213 Share on other sites More sharing options...
DarkWater Posted July 26, 2008 Share Posted July 26, 2008 use classes of css eg .. <?php $count++; if(($count % 2) == 1){ $class = "style1"; } else { $class = "style2"; } ?> <tr class="<?=$class ?>"> Don't use short tags. =P Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/#findComment-600216 Share on other sites More sharing options...
Zergman Posted July 26, 2008 Author Share Posted July 26, 2008 Don't use short tags. =P What do you mean? Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/#findComment-600271 Share on other sites More sharing options...
MFHJoe Posted July 26, 2008 Share Posted July 26, 2008 Use <?php echo $class; ?> instead of <?=$class ?>. Short tags don't work on some servers depending on how they're configured. Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/#findComment-600272 Share on other sites More sharing options...
DarkWater Posted July 26, 2008 Share Posted July 26, 2008 Don't use short tags. =P What do you mean? Umm, teng84 used short tags in his code. Instead of typing <?php echo $variable; ?>, short tags allow you to do <?=$variable?>. These are not guaranteed to work on all servers, and therefore are considered poor programming practice. (Wow, that was some pretty good alliteration. *pats self on back*) Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/#findComment-600273 Share on other sites More sharing options...
Zergman Posted July 26, 2008 Author Share Posted July 26, 2008 Good to know, thanks for the info Link to comment https://forums.phpfreaks.com/topic/116696-alternate-row-colors-from-database-query/#findComment-600325 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.