歡迎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。我假設你的查詢正在工作,所以你可以回顯你想基於顏色變化的值嗎? –