Jump to content

[SOLVED] Why am I only getting odd numbers?


RIRedinPA

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.