经测试代码如下:
<?PHP
/**
* 数据输出实现隔行变色
*
* @param
* @arrange (512.笔记) jb51.cc
**/
$host="localhost"; // Host name
$username=""; // @R_301_198@ username
$password=""; // @R_301_198@ password
$db_name="test"; // Database name
$tbl_name="test_@R_301_198@"; // Table name
// Connect to server and select databse
@R_301_198@_connect("$host","$username","$password")or die("cannot connect");
@R_301_198@_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=@R_301_198@_query($sql);
// Define $color=1
$color="1";
echo '<table width="400" border="1" align="center" cellpadding="2" cellspacing="0">';
while($rows=@R_301_198@_fetch_array($result)){
// If $color==1 table row color = #FFC600
if($color==1){
echo "<tr bgcolor='#FFC600'>
<td>".$rows['id']."</td><td>".$rows['name']."</td><td>".$rows['email']."</td>
</tr>";
// Set $color==2,for switching to other color
$color="2";
}
// When $color not equal 1,use this table row color
else {
echo "<tr bgcolor='#C6FF00'>
<td>".$rows['id']."</td><td>".$rows['name']."</td><td>".$rows['email']."</td>
</tr>";
// Set $color back to 1
$color="1";
}
}
echo '</table>';
@R_301_198@_close();
/*** 来自:编程之家 jb51.cc(jb51.cc) ***/
?>
@H_502_6@ 原文链接:https://www.f2er.com/php/528788.html