Jump to content

[SOLVED] different colours for table rows


wmguk

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/123006-solved-different-colours-for-table-rows/
Share on other sites

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>

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>
              <? } ?>

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.