gpt4 book ai didi

php - 将 php sql 结果从垂直转换为水平

转载 作者:太空宇宙 更新时间:2023-11-04 13:35:01 25 4
gpt4 key购买 nike

以下代码在垂直表中生成结果(一条记录)是否有任何方法可以像使用漂亮的样式一样转换为水平表。此外,如果可能的话,可以使用查询中的参数在弹出窗口中获取特定列, 使用 jquery 或 CSS

<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>

<?

$table = $_GET["table"];
$lon = $_GET["lon"];
$lat = $_GET["lat"];

$sql = "select
st_geometrytype(geom) as geometrytype,
st_area(geom) as area, *
from $table
where
st_contains(
geom,
st_transform(
st_setsrid(
st_makepoint($lon, $lat),
4326),
2276))";

$db = pg_connect("dbname=db user=user password=pass");
$result = pg_query($db, $sql);
while( $row = pg_fetch_assoc($result) )
{
print "<table>";
foreach ( array_keys($row) as $column_name )
{
if ( $column_name <> "geom" )
{
print "<tr>";
print "<th>" . $column_name . "</th>";
print "<td>" . $row[$column_name] . "</td>";
print "</tr>";
}
}
print "</table>";
}

?>

</body>
</html>

到目前为止,我正在使用这个 CSS 来设计我的表格。

th
{
text-align:right;
padding-right:0.5em;
}

td
{
text-align:center;
}

非常感谢..

最佳答案

你在循环运行的同时打印 tr ,所以它会生成 trs 显然它会是垂直的,让它水平,你的循环会变成这样;

while( $row = pg_fetch_assoc($result) )
{
print "<table>";
print "<tr>";
foreach ( array_keys($row) as $column )
{
if ( $column_name <> "geom" )
{


print "<th>" . $column . "</th>";

}
}

print "</tr>";
print "<tr>"; <-- this one here opening tag
foreach ( array_keys($row) as $column_name )
{
if ( $column_name <> "geom" )
{


print "<td>" . $row[$column_name] . "</td>";

}
}
print "</tr>"; <-- this one here closing tag
print "</table>";
}

关于php - 将 php sql 结果从垂直转换为水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23103514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com