欢迎SO。 有很多方法可以做到这一点。你需要弄清楚你的SQL Query将会是什么样子。既然你没有发布很多数据,我们很多人都会猜测。如果您可以为您的问题添加更多示例或代码,我们可以提供更多帮助。
所以,我建议这样的:
<style>
.myBox {
position:absolute;
left:471px;
top:94px;
width:204px;
height:183px;
filter:alpha(opacity=90);
opacity:0.90;
z-index:7;
}
.redBox {
background: red;
}
.greenBox {
background: green;
}
</style>
<?php
// perform MySQL Query (MySQLi or PDO)
// get results: $result, make a decision based on the condition
// will use MySQLi for example
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if ($result = $mysqli->query("SELECT * FROM someTable;")) {
while($row = $result->fetch_assoc()){
if($row['room'] == "empty"){
$colorClass = "greenBox";
} else {
$colorClass = "redBox";
}
}
$result->free();
}
$mysqli->close();
?>
<div id="wb_Shape6" class="myBox <?php echo $colorClass; ?>">
<img src="images/img0012.png" id="Shape6" alt="" style="width:204px;height:183px;">
</div>
什么服务器端语言是您使用解释SQL值? –
@Vlad Bardalez我使用wamp server 2.4和mysql作为语言我不认为我很了解你,因为我只是一个初学者 –
从你的其他文章我明白你正在使用PHP。我假设你的查询正在工作,所以你可以回显你想基于颜色变化的值吗? –