您好我的数据库中有一组示例数据:
+-----------+-------------+---------------+-------+
| IDNumber | SubjectCode | SubjectName | Grade |
+-----------+-------------+---------------+-------+
| 2012-1234 | IT-101 | Intro to I.T | 1.75 |
| 2012-1234 | IT-202 | Advanced I.T | 1.50 |
| 2012-5678 | CS-300 | Haskell Prog. | 1.00 |
+-----------+-------------+---------------+-------+
我的问题是如何根据数据自动在PHP中创建表。假设当我想搜索IDNumber 2012-1234时,它将自动创建4列和2行并在浏览器中打印,与IDNumber 2012-5678相同。
请给我一些提示,我会做其余的事。一些帮助/想法将更受赞赏。
答案 0 :(得分:0)
$result = $db->query("SELECT * FROM table");
$names_fetched = false;
$row_names = [];
while ($row = $result->fetchAssoc()) {
if (!$names_fetched) {
$row_names = array_keys($result); //row titles are here
$names_fecthed = true;
}
//other staff
}