我有這個php文件,我想從數據庫中檢索數據並以表格格式顯示。如何在php代碼嵌入時創建html元素的樣式?
<html>
<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="adminPanel.css"/>
</head>
<body>
<div class="header">
<h1>Admin</h1>
</div>
<div class="center">
<?php
include "db_connection.php";
$sql = "SELECT * FROM appointments;";
$result = mysqli_query($db,$sql);
If(mysqli_query($db,$sql) == TRUE){
?>
<table>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
<th>License</th>
<th>Engine</th>
<th>Appointment Date</th>
<th>Preferred Mechanic</th>
<?php
while($row = mysqli_fetch_assoc($result)){
?>
<td><?php echo $row['Name'];?></td></br>
<td><?php echo $row['Address'];?></td>
<td><?php echo $row['Phone'];?></td>
<td><?php echo $row['Car_license_No'];?></td>
<td><?php echo $row['Car_Engine_No'];?></td>
<td><?php echo $row['Date'];?></td>
<td><?php echo $row['Mechanic'];?></td>
<?php
}
?>
</table>
<?php
}
?>
</div>
<div class="footer">
<p id="lastMod">
<script language="Javascript">
document.write("Last modified on " + document.lastModified + " ");
</script>
</p>
</div>
</body>
</html>
但問題是我不能改變表中顯示的數據樣式。 .footer,.center,.header這些都顯示出完美的風格。但是,在php塊中寫入的html元素的樣式不起作用,例如,。
這裏是我的樣式表
.header{
background-color: black;
color: DC143C;
height: 150px;
margin-bottom: 0px;
font-family: "Impact"
}
.center{
background-image: url(background.jpg);
height: 400px;
margin-top: 0px;
margin-bottom: 0px;
}
.footer{
background-color: black;
font-family: "Impact";
color: DC143C;
margin-top: 82px;
height: 95px;
}
th, td{
color: white;
}
#lastMod{
margin-top: 0px;
padding: 5px;
}
搜索了很多,但havn`t發現任何相關的答案。提前致謝。
那麼,您通過php定義的html表格不包含任何在CSS樣式規則中使用的類名稱。那麼你爲什麼期望他們得到應用? – arkascha
在你的表中添加class,比如'class =「mytable」',並且通過指向父母的這種'.mytable th {color:#fff; }' –