Zend - The PHP Company




Tables

Add Code


Alternating table row colors  

Type: application
Added by: vnath
Entered: 13/04/2000
Last modified: 08/12/1999
Rating: *** (4 votes)
Views: 8862
An simple function designed to alternate row colors in a table.


<?php

function row_color($cnt,$even,$odd) {
    print (
$cnt%2) ? "<tr bgcolor="$odd"> : "<tr bgcolor="$even">";
}


Usage Example


<?php

//Basically you would call this function in a loop as you for example, output results returned from a database query. 


$result mysql_query("SELECT * from TABLE");

$cnt=0;
while(
$row mysql_fetch_row($result)) {
  
//Alternates between gray and white       
  
row_color($cnt++,"e0e0e0","FFFFFF");
  print 
"<td>YOUR_DATA</td></tr>n";
}

//This is a very simplified example, but should be sufficient to illustrate how to utilize this function.

?>


Rate This Script





Search



This Category All Categories