Zend - The PHP Company




Tables

Add Code


every other  

Type: code fragment
Added by: abb
Entered: 27/12/2002
Last modified: 02/12/2002
Rating: - (fewer than 3 votes)
Views: 4285
A simple code to present data from the database with altering background color


<?php
function everyother($bgcolor) {
 static 
$counter=0;

 if (
$counter == 0) {
  echo 
"$ind<tr style="background-color:$bgcolor">n";
 } else {
  echo 
"$ind<tr style="background-color:#ffffff">n";
 
}

 
$counter++;
}
?>


Usage Example


echo "<table>";
$q = mysql_query("SELECT * FROM table");
while($r = mysql_fetch_object($q)) {
 everyother("#eeeeee");
 echo "<td>$r->name</td>";
 echo "</tr>";
}
echo "</table>";


Rate This Script





Search



This Category All Categories