-1
A
回答
0
<?php
function db_select_with_col()
{
$rows = array();
$result = db_query("SELECT
student.StudentID,
student.`Name`,
attendance.Date,
CASE WHEN attendance.StudentID IS NOT NULL THEN 'Present' ELSE 'Absent' END as Attendance_Status
FROM
student
Left JOIN attendance ON student.StudentID = attendance.StudentID
WHERE
attendance.Date = '2015-03-30'");
// If query failed, return `false`
if ($result === false) {
return false;
}
// If query was successful, retrieve all the rows into an array
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
$colNames = array_keys(reset($rows));
foreach ($colNames as $colName) {
echo "<th>$colName</th>";
}
foreach ($rows as $row) {
echo "<tr>";
foreach ($colNames as $colName) {
echo "<td>" . $row[$colName] . "</td>";
}
echo "</tr>";
}
}
?>
想出如何做到這一點感謝的答案[這裏](https://stackoverflow.com/a/14430366/4680117)
相關問題
- 1. mysql:以標題顯示多個結果
- 2. PHP在MySQL表中顯示MySQL結果
- 3. 使用php以表格形式回顯mysql查詢結果
- 4. Mysql結果返回問題
- 5. PHP mysql結果問題
- 6. PHP不顯示MYSQL結果
- 7. 單個日期標題下的PHP回顯結果
- 8. PHP/MySQL以錯誤的順序回顯,還回顯列標題而不是該列的行值?
- 9. 符合MySQL的顯示結果在PHP
- 10. 在php中如何顯示mysql結果?
- 11. 結合兩個表並回顯結果(PHP MYSQL)
- 12. php在mysql數據提取查詢結果中回顯href
- 13. 顯示陣列結果PHP
- 14. 如何在PHP中回顯結果
- 15. 在PHP&mySQL中獲取最熱門搜索結果的標題
- 16. 顯示Mysql的結果在3列
- 17. PHP mysql在一個目標中顯示4個結果
- 18. 結果以單列顯示
- 19. 序列在用PHP從MySQL顯示結果
- 20. 列名顯示在查詢結果中mysql php
- 21. 標題顯示在PHP的MySQL通知
- 22. PHP回聲結果從MySQL SELECT
- 23. while循環不返回結果PHP/MySQL
- 24. php返回不同的mysql結果
- 25. MySQL/PHP只返回一個結果
- 26. PHP返回MySQL查詢結果
- 27. 搜索並回顯多個結果mysql
- 28. SQL Query在MySQL中返回完整結果,部分結果返回到PHP
- 29. PHP - Javascript結果在MySQL內
- 30. php數組中的MySQL結果問題
嘗試一些谷歌。 – 2015-03-30 20:40:11
兩者都太寬泛,不清楚你問的是什麼。 – 2015-03-30 20:40:43
我想使用mysql結果作爲列名 – 2015-03-30 20:45:59