2017-09-29 25 views
-4

這是一個停車場系統。使用while循環顯示不同的顏色

這是我的模塊之一。此代碼中的錯誤是狀態取消。

我希望它的狀態取消將在我的系統中顯示一個顏色黃色狀態離開但仍然不起作用。儲備,佔領和黃色只有我們運作。

<?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')"; 
     } 
     ?> 
+1

因此您給變量$ color分配了一個值。你究竟在哪裏使用它?...? – CBroe

+1

我不知道你是否忘記了它,但是在你的其他關閉「}」之後,你錯過了一個關閉「}」的while循環 – Schlodi

回答

1

只是一個建議,而不是severl如果你可以使用一個swicth聲明

<?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')"; 
     } 
    } 
?> 

並關閉循環

0

您可以簡單地使用,如果在這裏別的條件。並檢查您的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')"; 
    } 
} 

?>

0

希望你會足夠好理解下面。它是專爲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 %>