我想从 PostgreSQL DB 表中提取所有记录,并使用 HTML 中的表显示这些数据,而不指定列名。我有很多包含很多列的表,所以我希望我的 HTML 查询尽可能地响应。
使用下面的代码,我可以从数据库中查询数据并在浏览器上打印数据,但我必须指定要显示的列。
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8">
<title>Map</title>
</head>
<body onload="init()">
<h1>Map</h1>
<div>
<?php
$conn = pg_connect("host=localhost port=5432 dbname=visualization user=postgres password=*******");
$result = pg_query($conn,"SELECT * FROM myTable");
echo "<table>";
while($row=pg_fetch_assoc($result)){
echo "<tr>";
echo "<td width='200'>" . $row['lon'] . "</td>"; // set col manually
echo "<td width='200'>" . $row['lat'] . "</td>"; // set col manually
echo "</tr>";
}
echo "</table>";
pg_close($conn);
?>
</div>
</body>
</html>
结果如下:
我只显示 2 列,因为我手动指定了列。我想在不手动指定的情况下显示表中的所有列及其记录(最多 100 列)。如何做到这一点?
SMILET
杨__羊羊
慕少森