使用while循环显示不同的颜色

时间:2017-09-29 11:22:35

标签: php html database mysqli parking

这是一个停车场系统。

这是我的模块之一。此代码中的错误是状态取消。

我希望它的状态取消将在我的系统中显示一个颜色黄色,如状态离开但仍然无法正常运行。储备,占用和黄色只有我们运作。

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

3 个答案:

答案 0 :(得分:1)

如果你可以使用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 循环

答案 1 :(得分:0)

您可以在此处使用if else条件。并检查你的位置

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

&GT;

答案 2 :(得分: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 %>