我有一个 SQL 查询,它看起来像:
`SELECT * FROM table LIMIT 5;`
事实上,我使用 mysql 的免费员工数据库,查询是:
`SELECT * FROM employees LIMIT 5;`
现在我有一个 PHP 函数,它将选定的数据输出到一个 HTML 表中,如下所示:
function outputTable($query, $link){
//Verbindung zur Datenbank inkludieren
require_once('./config.php');
//auffangen der Rückgabe
$erg = mysqli_query($link, $query);
//bestimmt Anzahl der Spalten (aocol = Amount Of COLumns)
//counts the amount of columns
$aocol = count(mysqli_fetch_array($erg, MYSQLI_NUM));
//table head
$head = "";
for($x = 0; $x < $aocol; $x++) {
//legt alle Informationen des Feldes $x in $finfo, darunter auch den Namen der Spalte.
//puts all information of the field $x in $finfo, also the name of the column
$finfo = mysqli_fetch_field_direct($erg, $x);
//Schreibt die Kopfzeile der Tabelle
//writes the table's head
$head .= "<th>".$finfo->name."</th>";
}
//only if style.css included-->irrelevant
echo '<div class="table"><table id="table">';
//output of table's head
echo "<th>$head</th>";
//output of table's body --> here must be the bug, I think
while($zeile = mysqli_fetch_array($erg, MYSQLI_NUM)) {
//new tablerow
echo "<tr>";
//filling the row
foreach($zeile as $feld) {
//format for numbers
$ra = preg_match('/^\d+$/',$feld) ? ' align="right"' : '';
//displaying table data
echo "<td$ra>".$feld."</td>";
}
}
//closing table and layout
echo '</table></div>';
}
慕婉清6462132
至尊宝的传说