交替颜色显示Mysql的记录
时间:2007-02-17 来源:PHP爱好者
<?
$connection = mysql_connect("hostname","username","password");
$db = mysql_select_db("db_name", $connection);
$sql = mysql_query("SELECT * FROM table_name ORDER BY field1 ASC");
echo "<table cellpadding=0 cellspacing=0 border=0><tr><td><b>Field1</b></td><td><b>Field2</b></td><td><b>Field3</b></td></tr>";
$alternate = "2";
while ($row = mysql_fetch_array($sql)) {
$field1 = $row["field1"];
$field2 = $row["field2"];
$field3 = $row["field3"];
if ($alternate == "1") {
$color = "#ffffff";
$alternate = "2";
}
else {
$color = "#c0c0c0";
$alternate = "1";
}
echo "<tr bgcolor=$color><td>$field1</td><td>$field2</td><td>$field3</td></tr>";
}
echo "</table>";
?>
php爱好者站 http://www.phpfans.net php动态|php基础|php进阶|php模板.
$connection = mysql_connect("hostname","username","password");
$db = mysql_select_db("db_name", $connection);
$sql = mysql_query("SELECT * FROM table_name ORDER BY field1 ASC");
echo "<table cellpadding=0 cellspacing=0 border=0><tr><td><b>Field1</b></td><td><b>Field2</b></td><td><b>Field3</b></td></tr>";
$alternate = "2";
while ($row = mysql_fetch_array($sql)) {
$field1 = $row["field1"];
$field2 = $row["field2"];
$field3 = $row["field3"];
if ($alternate == "1") {
$color = "#ffffff";
$alternate = "2";
}
else {
$color = "#c0c0c0";
$alternate = "1";
}
echo "<tr bgcolor=$color><td>$field1</td><td>$field2</td><td>$field3</td></tr>";
}
echo "</table>";
?>
php爱好者站 http://www.phpfans.net php动态|php基础|php进阶|php模板.
相关阅读 更多 +