[英]Displaying a different colors using while loop
這是一個停車場系統。
這是我的模塊之一。 此代碼中的錯誤是狀態取消。
我希望狀態取消將在我的系統中顯示黃色,就像狀態離開一樣,但仍然無法正常工作。 儲備,占用和黃色只有我們運作。
<?php include 'dbcon.php';
$result = mysqli_query($con,"SELECT * FROM `zonenumber` WHERE 1");
while ($fetch = mysqli_fetch_array($result))
{
$name = $fetch['name'];
$status = $fetch['status'];
if ($status == 'Cancel') $color = 'yellow';
if ($status == 'Reserved') $color = 'green';
if ($status == 'Occupied') $color = 'red';
if ($status == 'Leave') $color = 'yellow';
if ($color != 'yellow')
{
$print = "javascript:popUp('zonestatus_1.php?id=$name');";
}
else
{
$print = "javascript:alert('There is NO Information Available')";
}
?>
如果您可以使用 swicth 語句,則只是一個建議而不是 severl
<?php include 'dbcon.php';
$result = mysqli_query($con,"SELECT * FROM `zonenumber` WHERE 1");
while ($fetch = mysqli_fetch_array($result))
{
$name = $fetch['name'];
$status = $fetch['status'];
switch ($status) {
case 'Cancel':
case 'Leave':
$color = 'yellow';
break;
case 'Reserved':
$color = 'green';
break;
case 'Occupied':
$color = 'red';
break;
// eventually you can manage default
default:
// your code for default
break;
}
if ($color != 'yellow')
{
$print = "javascript:popUp('zonestatus_1.php?id=$name');";
}
else
{
$print = "javascript:alert('There is NO Information Available')";
}
}
?>
並關閉你的while循環
您可以在這里簡單地使用 if else 條件。 並檢查您的 where 條件
<?php
include 'dbcon.php';
$result = mysqli_query($con,"SELECT * FROM `zonenumber` WHERE 1");
while ($fetch = mysqli_fetch_array($result))
{
$name = $fetch['name'];
$status = $fetch['status'];
if($status == 'Cancel')
{
$color = 'yellow';
}
elseif($status == 'Reserved')
{
$color = 'green';
}
elseif($status == 'Occupied')
{
$color = 'red';
}
elseif($status == 'Leave')
{
$color = 'yellow';
}
else
{
$color = ''; // your default color
}
if ($color != 'yellow')
{
$print = "javascript:popUp('zonestatus_1.php?id=$name');";
}
else
{
$print = "javascript:alert('There is NO Information Available')";
}
}
?>
希望你能很好地理解下面的內容。 它是為 VBScript 設計的...
雖然有結果,但顏色是白色的。 環形。 如果顏色為白色(顯示結果后),則顏色現在為灰色。 環形。 如果顏色是灰色 - 再次更改!
<%
xBg="#cccccc"
while not rs.eof
%>
<tr style="background-color: <% = xBg %>">
<td>FIELDRESULT</td>
</tr>
<% if xBg="#cccccc" then xBg="#ffffff" else xBg="#cccccc"
rs.MoveNext
wend %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.