Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.