I have a while loop where I want to compare the current variable ($high) to the previous one. If the value is higher I want to show a green background and if it is lower I want to show a red background.
At the moment, if the value is higher, then it shows a red background, also it only seems to compare the latest result and not all of the values in the loop.
$previous = 0;
while ($row =mysql_fetch_assoc($result)){
$high = $row['High'];
if ($high > $previous){
?> <span style="background:green"><?php echo $row['High']; ?></span><?PHP
}else{
?> <span style="background:red"><?php echo $row['High']; ?></span><? PHP
}
$previous = row;
}
mysql_*is deprecated and removed library now, so upgrade yourself to PHP7 along withmysqli_*orPDO. 2.$previous = row;needs to be$previous = $high;