wmguk Posted September 6, 2008 Share Posted September 6, 2008 Hi guys, I have a php table that is auto populated by a query. What i wanted was row1 background white, row2 background red, then repeat... <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="21" colspan="3">Below is a current list of members within the Dereham BNI - Windmill Chapter.</td> </tr> <tr> <td width="350" height="21" background="images/bni_header_line.jpg"><div align="center"><strong>Business Classification</strong></div></td> <td width="190" background="images/bni_header_line.jpg" class="pageheader"><div align="center"><strong>Business Name</strong></div></td> <td width="60" background="images/bni_header_line.jpg"><div align="center"></div></td> </tr> <? include "admin/scripts/connection.php"; if (!$con) { die( 'Could not connect: ' . mysql_error() ); } mysql_select_db($db, $con); //Show the list of Industy $sql = "SELECT * FROM industry"; $result = mysql_query( $sql ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sql<br><br>" ); while($row = mysql_fetch_array($result)) { if ($row['used'] == "0"){ $coname = "Vacancy" ; } else { $coname = $row['coname'] ; } ?> <tr> <td height="22" background="images/bni_line.gif"><strong><? echo $row['industry']; ?></strong></td> <td background="images/bni_line.gif" class="pageheader"><div align="center"><? echo $coname; ?> </div></td> <td align="middle" valign="center" background="images/bni_grey_line.gif"><div align="center"><strong> <a href="pop.php?coname=<? echo $coname ; ?>" onclick="window.open('pop.php?coname=<? echo $coname ; ?>','popup','width=500,height=215,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=300'); return false">Info</a> </strong></div></td> </tr><? } ?> </table> what would be the best way to colour the rows? Quote Link to comment https://forums.phpfreaks.com/topic/123006-solved-different-colours-for-table-rows/ Share on other sites More sharing options...
BlueSkyIS Posted September 6, 2008 Share Posted September 6, 2008 something like: $c_toggle = 1; // color toggle while($row = mysql_fetch_array($result)) { if ($row['used'] == "0"){ $coname = "Vacancy" ; } else { $coname = $row['coname'] ; } if ($c_toggle == 1) { $bg_color = '#ff0000'; $c_toggle = 0; } else { $bg_color = '#ffffff'; $c_toggle = 1; } ?> <tr bgcolor='<?php echo $bg_color; ?>'> <td height="22" background="images/bni_line.gif"><strong><? echo $row['industry']; ?></strong></td> <td background="images/bni_line.gif" class="pageheader"><div align="center"><? echo $coname; ?></div></td> <td align="middle" valign="center" background="images/bni_grey_line.gif"><div align="center"><strong> <a href="pop.php?coname=<? echo $coname ; ?>" onclick="window.open('pop.php?coname=<? echo $coname ; ?>','popup','width=500,height=215,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=300'); return false">Info</a> </strong></div></td> </tr> <?php } // while records ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/123006-solved-different-colours-for-table-rows/#findComment-635166 Share on other sites More sharing options...
wmguk Posted September 6, 2008 Author Share Posted September 6, 2008 thank you It flashed red, but then went white again... <? include "admin/scripts/connection.php"; if (!$con) { die( 'Could not connect: ' . mysql_error() ); } mysql_select_db($db, $con); //Show the list of Industy $sql = "SELECT * FROM industry"; $result = mysql_query( $sql ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sql<br><br>" ); $c_toggle = 1; // color toggle while($row = mysql_fetch_array($result)) { if ($row['used'] == "0"){ $coname = "Vacancy" ; } else { $coname = $row['coname'] ; } if ($c_toggle == 1) { $bg_color = '#ff0000'; $c_toggle = 0; } else { $bg_color = '#ffffff'; $c_toggle = 1; } ?> <tr bgcolor='<?php echo $bg_color; ?>'> <td height="22" background="images/bni_line.gif"><strong><? echo $row['industry']; ?></strong></td> <td background="images/bni_line.gif" class="pageheader"><div align="center"><? echo $coname; ?></div></td> <td align="middle" valign="center" background="images/bni_grey_line.gif"><div align="center"><strong> <a href="pop.php?coname=<? echo $coname ; ?>" onclick="window.open('pop.php?coname=<? echo $coname ; ?>','popup','width=500,height=215,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=300'); return false">Info</a> </strong></div></td> </tr> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/123006-solved-different-colours-for-table-rows/#findComment-635167 Share on other sites More sharing options...
BlueSkyIS Posted September 6, 2008 Share Posted September 6, 2008 one problem might be your use of background images in the <td>'s. maybe try removing them: <td height="22" background="images/bni_line.gif"> should be... <td height="22"> Quote Link to comment https://forums.phpfreaks.com/topic/123006-solved-different-colours-for-table-rows/#findComment-635168 Share on other sites More sharing options...
wmguk Posted September 6, 2008 Author Share Posted September 6, 2008 one problem might be your use of background images in the <td>'s. maybe try removing them: <td height="22" background="images/bni_line.gif"> should be... <td height="22"> Bingo! Excellent! thanks for your help guys! Quote Link to comment https://forums.phpfreaks.com/topic/123006-solved-different-colours-for-table-rows/#findComment-635169 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.