My task is to create a BMI table.
<?php
$minWeight = $_GET['min_weight']; //Getting values from HTML user input
$maxWeight = $_GET['max_weight'];
$minHeight = $_GET['min_height'];
$maxHeight = $_GET['max_height'];
$tableStr = "<html>
<head>
<style>
table, th, td {border: 1px solid black;}
</style>
</head>
<body>
<table style=width:100%>
"; //table formating
//This is ugly. I would like to merge this into the existing for loop
$tableStr .= "<th></th>";
for($j = $minWeight; $j <= $maxWeight; $j += 5) {
$tableStr .= "<th>" . $j ."</th>";
}
//Up to here
for($i = $minHeight; $i <= $maxHeight; $i += 5){ //creating the number of headers
$tableStr .= "<tr>";
$tableStr .= "<th>" . $i . "</th>";
for($j = $minWeight; $j <= $maxWeight; $j += 5) {
//$tableStr .= "<th>" . $j ."</th>"; //print this alongside the line below messes up the table
$tableStr .= "<td>" . intval($j / pow(($i/100),2)) . "</td>"; //This prints the result in the columns
}
$tableStr .= "</tr>";
}
$tableStr .= "</table>
</body>
</html>"; //end table format
echo $tableStr;
?>
I have got it almost working. The only thing lacking is adding the weight on top of the table as an x-axis. I have tried, I can't get both the BMI results from the calculation and the actual weight untouched to show on the table.
The only way I have been able to do it was by creating a separate for loop and printing a row of the values, but I feel like one should be able to do inside the already existing nested for loop.