小编典典
这是您要查找的内容的完整示例:
使用php从mysql中提取一些数据
将该数据放入html表
将交替的彩色行应用于表
对于样式,我作弊了一点,并使用jquery,我发现它比您尝试做的要容易一些。
另外,请记住$ row [field]区分大小写。 因此$ row [id]!= $ row [ID]。
希望这可以帮助:
tr.header
{
font-weight:bold;
}
tr.alt
{
background-color: #777777;
}
$(document).ready(function(){
$('.striped tr:even').addClass('alt');
});
$server = mysql_connect("localhost","root", "");
$db = mysql_select_db("MyDatabase",$server);
$query = mysql_query("select * from employees");
?>
Id | Name | Title |
while ($row = mysql_fetch_array($query)) {
echo "
";echo "
".$row[ID]."";echo "
".$row[Name]."";echo "
".$row[Title]."";echo "
";}
?>
这是仅使用PHP替代样式的表代码,就像您在示例中尝试的那样:
Id | Title | Date |
$i = 0;
while ($row = mysql_fetch_array($query)) {
$class = ($i == 0) ? "" : "alt";
echo "
";echo "
".$row[ID]."";echo "
".$row[Name]."";echo "
".$row[Title]."";echo "
";$i = ($i==0) ? 1:0;
}
?>
2020-05-17