Zend - The PHP Company




Tables

Add Code


Alternative Colored Rows  

Type: code fragment
Added by: saidbakr
Entered: 06/02/2003
Last modified: 02/12/2002
Rating: - (fewer than 3 votes)
Views: 4571
This code will show you how easily to handle an alternative colored rows using defined function I called it as foxcol($x) where $x is int


<?
       $y 
0;//will be needed later to make counter inside the loop
    
function foxcol($x)// The function which will print the color name

    
{
            
$x++;
       if (
$x%0.5)
       {
           print(
"red");
       }
       else
       {
           print(
"yellow");
       }
   }
   
?>
   <table width="100%" border=1>
   <?

   
for ($i 0$i 14; ++$i)://The loop inwhich rows will be repeated
      
++$y;// The counter which will passed throgh the function to produce the color
   
?>
   <tr bgcolor="<?foxcol($y)?>">
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   </tr>
   <?
   
endfor;
   
?>
   </table>


Usage Example




Rate This Script





Search



This Category All Categories