RIRedinPA Posted May 13, 2009 Share Posted May 13, 2009 I'm trying to build an html table which shows the tables within a database associated with x. I want to alternate row colors when I display it so I am increasing a variable by 1, using mod to see if it is even or not and setting css color appropriately. Problem is my result numbers are all odd, 1, 3, 5, 7, 9 and so all the rows are the same color. Code to get tables <div id="groupstable" style="height: 150px; overflow-y: scroll; background-color: white;"><table cellpadding="3" cellspacing="0" border="0" width="185" style="border-top: 1px solid #333; border-left: 1px solid #333;"> <?php $query = "SHOW TABLES"; $result = mysql_query($query); $a=0; while($showtablerow = mysql_fetch_array($result)) { $a = $a+1; //background color if( $odd = $a%2 ) { $backgroundcolor = "#eee;"; } else { $backgroundcolor = "#c6dcf9;"; } $tablename = $showtablerow[0]; if (strstr($tablename, $loadmagcode) == true) { if(strstr($tablename, "_history") == false) { print "<tr valign=\"top\" style=\"background-color: $backgroundcolor\"><td style=\"border-right: 1px solid #333; border-bottom: 1px solid #333; font-size: .8em;\">$showtablerow[0] $a</td></tr>"; } } } ?> </table></div> $loadmagcode in this case = "AA" results: AA_03162009 1 AA_04202009 3 AA_09012008 5 AA_09082008 7 AA_09152008 9 Quote Link to comment https://forums.phpfreaks.com/topic/157970-solved-why-am-i-only-getting-odd-numbers/ Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Put $a = $a+1 before print. Quote Link to comment https://forums.phpfreaks.com/topic/157970-solved-why-am-i-only-getting-odd-numbers/#findComment-833226 Share on other sites More sharing options...
RIRedinPA Posted May 13, 2009 Author Share Posted May 13, 2009 Put $a = $a+1 before print. Thanks, duh. : D Quote Link to comment https://forums.phpfreaks.com/topic/157970-solved-why-am-i-only-getting-odd-numbers/#findComment-833234 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.