Meine Aufgabe ist es, eine BMI-Tabelle zu erstellen.Hinzufügen von Kopfzeilen in HTML-Tabellen
<?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> \n <head> \n <style> \n table, th, td {border: 1px solid black;}
\n </style> \n </head> \n <body> \n <table style=width:100%> \n"; //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> \n </body> \n </html>"; //end table format
echo $tableStr;
?>
Ich habe es fast funktioniert. Das einzige, was fehlt, ist das Gewicht auf der Oberseite des Tisches als x-Achse hinzuzufügen. Ich habe versucht, ich kann nicht sowohl die BMI-Ergebnisse von der Berechnung und das tatsächliche Gewicht unberührt auf dem Tisch zu zeigen.
Die einzige Möglichkeit, die ich tun konnte, war durch Erstellen einer separaten for-Schleife und Drucken einer Reihe der Werte, aber ich fühle mich wie in der bereits vorhandenen geschachtelten for-Schleife tun können.
Ich rende keine Textdatei, ich erstelle eine Tabelle dynamisch. – Pete
entfernen Sie einfach Ihre \ n in Ihrem Code –