title: Adding headers in HTML tables
body: <p>My task is to create a BMI table.</p>
  
  <pre><code>&lt;?php
  
  $minWeight = $_GET['min_weight']; //Getting values from HTML user input
  $maxWeight = $_GET['max_weight'];
  $minHeight = $_GET['min_height'];
  $maxHeight = $_GET['max_height'];   
  
  $tableStr = "&lt;html&gt; \n &lt;head&gt; \n &lt;style&gt; \n table, th, td {border: 1px solid black;} 
  \n &lt;/style&gt; \n &lt;/head&gt; \n &lt;body&gt; \n &lt;table style=width:100%&gt; \n";  //table formating
  
  //This is ugly. I would like to merge this into the existing for loop
  $tableStr .= "&lt;th&gt;&lt;/th&gt;";
  for($j = $minWeight; $j &lt;= $maxWeight; $j += 5) {
          $tableStr .= "&lt;th&gt;" . $j ."&lt;/th&gt;";
  }
  //Up to here
  
  for($i = $minHeight; $i &lt;= $maxHeight; $i += 5){ //creating the number of headers
      $tableStr .= "&lt;tr&gt;"; 
      $tableStr .= "&lt;th&gt;" . $i . "&lt;/th&gt;";
      for($j = $minWeight; $j &lt;= $maxWeight; $j += 5) {
          //$tableStr .= "&lt;th&gt;" . $j ."&lt;/th&gt;"; //print this alongside the line below messes up the table
          $tableStr .= "&lt;td&gt;" . intval($j / pow(($i/100),2)) . "&lt;/td&gt;"; //This prints the result in the columns
      }   
      $tableStr .= "&lt;/tr&gt;";
  } 
  
  $tableStr .= "&lt;/table&gt; \n &lt;/body&gt; \n &lt;/html&gt;"; //end table format
  echo $tableStr;  
  
  ?&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>