1
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {

i want the if statement to show green if result is 1,2,3 and red if 0

if($row['9am'] > 3) {
    $colour="#FF0000";
} else {
    $colour="#66ff33";
}

this will also be used for the other times so how would i replicate to all times

print " <tr>
<td>{$row['17th may 2017']}    </td> 
<td bgcolor=\"$colour\"> {$row['9am']} </td> 
<td>{$row['10am']}    </td> 
<td>{$row['11am']}    </td> 
<td>{$row['12pm']}    </td> 
<td>{$row['13pm']}    </td> 
<td>{$row['14pm']}    </td> 
<td>{$row['15pm']}    </td> 
<td>{$row['16pm']}    </td> 
  </tr> ";


}

print '</table>';

}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
c.teat
  • 11
  • 1
  • ok? and is there a question here? –  Dec 13 '16 at 01:31
  • how can i make the if statement display a certain colour in a cell that has a value between 0 and 3 – c.teat Dec 13 '16 at 01:33
  • currently your checking for greater then 3 =red or less than =green –  Dec 13 '16 at 01:35
  • 2
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Dec 13 '16 at 01:36
  • 1
    Rush into the late 20th century and use a `style="background-color: #111111"` rather than `bgcolor` – RiggsFolly Dec 13 '16 at 01:39
  • i am quite new to this as you can tell but what it does is colour a whole row i want it to colour the cell that has a value in it either red for 0 and green for 1,2 or 3 because not all in the cells in the row have values – c.teat Dec 13 '16 at 01:45
  • it seems to be just primary school math\logic there are a couple of options: if 0 else not. if you know the value can only be 0,1,2,3 or if 0 or less than or equal to 3 if there could be values over 3 –  Dec 13 '16 at 01:51
  • since the color only has to be either green or red, why not try this. ` 3 || $row['9am'] == 0?'#FF0000':'#66ff33')."'> {$row['9am']} ` for every ``. this statement `($row['9am'] > 3 || $row['9am'] == 0?'#FF0000':'#66ff33')` is the shorthand `if else` statement. – Mark Vincent Manjac Dec 13 '16 at 02:42

0 Answers0