I have created a heatmap function that I am going to use to fill the cells of a table in html using PHP 7.2.
Here is my function:
function bg($latency) {
if ($latency ==0) {echo '#11FFFF';}
elseif ($latency <30) {echo '#22FFFF';}
elseif ($latency <60) {echo '#33FFFF';}
elseif ($latency <90) {echo '#44FFFF';}
elseif ($latency <120) {echo '#55FFFF';}
elseif ($latency <150) {echo '#66FFFF';}
elseif ($latency <180) {echo '#77FFFF';}
elseif ($latency <210) {echo '#88FFFF';}
elseif ($latency <240) {echo '#99FFFF';}
elseif ($latency <270) {echo '#AAFFFF';}
elseif ($latency <300) {echo '#BBFFFF';}
elseif ($latency >=300) {echo '#CCB27F';}
}
I pull values from a MySQL table with a simple select statement and then try to build the table with the following code snippet:
while($row = mysqli_fetch_assoc($result)) {
echo '<tr><td>'.$row['origin'].'</td><td bgcolor='.bg($row['lt01']).'>'.$row['lt01'].'</td></tr>';
}
But for some reason the output is garbled with the function output appearing before the HTML source:
#11FFFF<tr><td>LT01</td><td bgcolor=>0</td></tr>
#22FFFF<tr><td>LT02</td><td bgcolor=>11</td></tr>
#44FFFF<tr><td>LT03</td><td bgcolor=>62</td></tr>
#44FFFF<tr><td>LT04</td><td bgcolor=>74</td></tr>
#99FFFF<tr><td>LT05</td><td bgcolor=>214</td></tr>
I cannot for the life of me figure this out.