Display database values in different colours

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    #1

    Display database values in different colours

    In my web page there is a table for displaying database values. For one column displays connected or Disconnected. If the database values is Disconnected i want to display the value in red color. How can i do that? This is my existing code.

    [PHP]<td width="121" class="IDTableC ell"><?php "$StationID " ;?> </td>[/PHP]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You'd need to somehow determine whether it's d/c or connected. So best way would be to store a value in your database (0 = d/c, 1 = connected).

    [php]
    if($status == 1)
    echo "<td width=\"121\" style=\"color: green;\" class=\"IDTable Cell\">$Station ID</td>";
    else
    echo "<td width=\"121\" style=\"color: red;\" class=\"IDTable Cell\">$Station ID</td>";
    [/php]

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by markusn00b
      You'd need to somehow determine whether it's d/c or connected. So best way would be to store a value in your database (0 = d/c, 1 = connected).

      [php]
      if($status == 1)
      echo "<td width=\"121\" style=\"color: green;\" class=\"IDTable Cell\">$Station ID</td>";
      else
      echo "<td width=\"121\" style=\"color: red;\" class=\"IDTable Cell\">$Station ID</td>";
      [/php]
      If you store the color in a variable, you make the coding shorter and cleaner.

      Comment

      Working...