Search:

Categories



Alternate Row Colours

<? 
 
// Header rows 
print ("<body bgcolor=black text=white>"); 
print ("<table border=1 width=100%> 
<tr> 
    <td width=18%><font face=Verdana, Arial, Helvetica, sans-serif size=2><b>Name</b></font></td> 
    <td width=82%><font face=Verdana, Arial, Helvetica, sans-serif   
size=2><b>Email</b></font></td>"); 
 
// DB connection information 
$connection = mysql_connect("localhost","username","password"); 
$db = mysql_select_db("database", $connection); 
 
// SQL Query 
$sql = mysql_query("SELECT * FROM table"); 
 
$alternate = "2"; // number of alternating rows 
while ($row = mysql_fetch_array($sql)) { 
$name = $row["name"]; //name of field 
$email = $row["email"]; 
 
if ($alternate == "1") { 
$colour = "#000000"; 
$alternate = "2"; 
} 
 
else { 
$colour = "#464646"; 
$alternate = "1"; 
} 
 
print ("</tr><tr><td bgcolor=$colour width=18%><font face=Verdana, Arial, Helvetica,   
sans-serif size=2>$name</font></td><td bgcolor=$colour width=82%> 
<font face=Verdana, Arial, Helvetica, sans-serif size=2>$email</font></td> 
</tr>"); 
} 
print ("</table>"); 
 
?>
Share

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  


*