Click here to Skip to main content
15,664,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am looking to build an HTML table with BMI values based on these 4 input values: ‘min_weight’, ‘max_weight’ (input in kg) ‘min_height’, ‘max_height’ (input in cm)

The finished table will have rows headed by ‘min_weight’ to ‘max_weight’ (incremented in steps of 5), and columns headed by ‘min_height’ to ‘max_height’ (incremented in steps of 5). The formula used to calculate these BMI values is: weight/height

So far I have created the form that gathers the input data for the table. I am new to PHP and am currently figuring out the basics and I will be grateful for any help/guidance given.

What I have tried:

<pre lang="HTML">
<!DOCTYPE html>
<form action="bmi.php" method="get" id="bmi">
    <table border="1">
        <th scope="col">Key</th>
        <th scope="col">Value</th>
        <td><label for="min_weight">Minimum Weight (min_weight)</label></td>
          <input name="min_weight" type="text" class="larger" id="min_weight" value="50" size="5" />
        <td><label for="max_weight">Maximum Weight (max_weight)</label></td>
        <td><input name="max_weight" type="text" class="larger" id="max_weight" value="90" size="5" /></td>
        <td><label for="min_height">Minimum Height (min_height)</label></td>
        <td><input name="min_height" type="text" class="larger" id="min_height" value="150" size="5" /></td>
        <td><label for="max_height">Maximum Height (max_height)</label></td>
        <td><input name="max_height" type="text" class="larger" id="max_height" value="190" size="5" /></td>
        <td><label for="submit">Submit</label></td>
        <td><input type="submit" name="submit" id="submit" value="Submit" class="larger" /></td>
Updated 15-Aug-21 22:30pm
Gerry Schmitz 16-Aug-21 1:00am    
BMI is a function of weight and height (and sometimes age). The usual thing is to just prompt for those variables and give one answer; not a table.
The Melon 17-Aug-21 20:22pm    
but I'm supposed to create a table with the 4 input values using a mix of javascript and php

1 solution

You just need some loops to generate the table data. for example this will generate a row of items with weights from 10 to 35:
echo "<tr>\n";
for ($weight = 10; $weight < 40; $weight += 5)
  echo "<td>$weight</td>";
echo "\n</tr>\n";

You just need to add similar loops for the other values.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900