可以通过以下步骤实现:
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);
while ($field = mysqli_fetch_field_direct($result)) {
echo $field->name;
}
echo "<table>";
echo "<tr>";
while ($field = mysqli_fetch_field_direct($result)) {
echo "<th>" . $field->name . "</th>";
}
echo "</tr>";
// 显示数据行
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
foreach ($row as $value) {
echo "<td>" . $value . "</td>";
}
echo "</tr>";
}
echo "</table>";
这样,你就可以使用PHP选择和显示MYSQL列名了。请注意,以上代码仅为示例,实际应用中可能需要根据具体情况进行适当修改。
领取专属 10元无门槛券
手把手带您无忧上云