【发布时间】:2021-01-10 12:09:52
【问题描述】:
我需要在 HTML 中对 MYSQL 数据库值使用 css 样式。在我的素食数据库行中,我的“Y”值表示“是”,“N”表示“否”。我需要将 css 应用于“Y”和“N”值,以便我可以使用 css 设置它们的样式?我正在使用 PHP 来显示我的页面。
if ($result1->num_rows > 0) {
// output data of each row
while($row = $result1->fetch_assoc()) {
echo '<h3 class="auto-title"> ' , $row["food"] , ' </h3>' , $row["description"] , '</br>
<div class="vegetarian"> ' , $row["vegetarian"] , ' </div>
<b class="auto-price"> ' , $row["price"] , ' </b><br> ';
}
}
我尝试过使用下面的这个 CSS,但没有任何乐趣。
div.vegetarian [value="Y"] {
color: red;
}
【问题讨论】:
-
echo '<div class="vegetarian ', ($row['vegetarian'] == 'Y' ? 'vegetarian-y' : 'vegetarian-n'), '"> ...'…?
标签: php html css mysql database