以下代码在垂直表中生成结果(一条记录)是否有任何方式可以转换为水平,就像使用漂亮的样式一样..此外,如果可以使用查询中的参数在弹出窗口中获取某些列,使用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;
}
非常感谢..
答案 0 :(得分:1)
你正在循环运行的同时打印tr
,所以它会使tr
显然是垂直的,为了使它成为水平,你的循环将是这样的; < / p>
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>";
}
答案 1 :(得分:0)
水平显示8个元素的代码。
<table>
<?if($c==8){echo "<tr >";$c=0; }<td> ?>
// your elements
<? echo "</td>";
$c++;?>
</tr>
</table>