if, else if echo statement

if-statement, mysql, php

Solution

You can do this:

 if($row['play']  == 1){
    echo "<td bgcolor='green'>Yes</td>";
    }
 else if ($row['play']  == 0){
    echo "<td bgcolor='yellow'>No</td>";
    }    

but I'd say that `switch/case` thing is more comfortable:

switch( $row['play'] ) {
   case 1:
       echo "<td bgcolor='green'>Yes</td>";
       break;

   default:
       echo "<td bgcolor='yellow'>No</td>";
       break;
}

Problem

If the value is 1 the cell bg is green with the # 1 in the cell If the value is 0 the cell bg is yellow with a 0 in it. I would like to display "Yes" instead of "1" and "No" instead of "0" ``` if($row['play'] == 1){ echo "<td bgcolor='green'>" . $row['play'] . "</td>"; } else if ($row['play'] == 0){ echo "<td bgcolor='yellow'>" . $row['play'] . "</td>"; } ``` The values come from a checkbox (1) and a hidden field (0) The MySQL field is BOOL. Is there an easier/better way to achieve this?

Original source