-4

This is a parking lot system.

This is the one of my module. The error in this codes is the status cancel.

I want it the status cancel is will display in my system a color yellow like the status leave but still its not functioning. the reserve , occupied and yellow only us functioning.

<?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')";
      }
      ?>
Deepak Dholiyan
  • 1,774
  • 1
  • 20
  • 35
  • 1
    So you assigned a value to the variable $color. And where exactly are you using that afterwards …? – CBroe Sep 29 '17 at 11:26
  • 1
    I don't know if you just forgot it, but you are missing a closing "}" for your while-loop after the closing "}" of your else – Schlodi Sep 29 '17 at 11:27

3 Answers3

1

Just a suggestion instead of severl if you could use a swicth statement

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

and close your while loop

B. Desai
  • 16,414
  • 5
  • 26
  • 47
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

You can simply use if else conditions here. And check your where condition as well

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

?>

Subhash Shipu
  • 343
  • 1
  • 4
  • 15
0

Hopefully you'll be good enough to understand the below. It's designed for VBScript...

While there is a result, the color is white. Loop. If the color is white (after the result is shown), the color is now grey. Loop. If the color is grey - change again!

<%
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 %>