我有以下格式的postgresql数据库表
Row_no Col_no Name
1 1 Test
1 2 Result
1 3 Observation
2 1 abc
2 2 Result1
2 3 observation1
我想用以下格式在html表中显示数据
Test Result Observation
abc Result1 observation1
那么有人可以建议我怎么做吗?
答案 0 :(得分:2)
方法:
按行和列索引
将它们存储到输出数组中喜欢:
$ARR_OUPUT[$row_no][$col_no] = $name;
现在您可以将它们打印到html表中
喜欢:
echo '<table>';
foreach($ARR_OUTPUT as $key=>arr_temp)
{
echo '<tr>';
foreach($arr_temp as $name)
{
echo '<td>'.$name.'</td>';
}
echo '</tr>';
}
echo '<table>';
你的数组看起来像这样
Array
(
[1] => Array
(
[1] => Test
[2] => Result
[3] => Observation
)
[2] => Array
(
[1] => abc
[2] => Result1
[3] => Observation1
)
)
答案 1 :(得分:-2)
尝试以下代码
<table>
<thead>
<tr>
<th>Test</th>
<th>Result</th>
<th>Observation</th>
</tr>
</thead>
<tbody>
<?php
$con=mysqli_connect("localhost","username","password","dbname");
$sql=mysqli_query($con, "SELECT * from Name");
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo $row['Test'];?></td>
<td><?php echo $row['Result'];?></td>
<td><?php echo $row['Observation'];?></td>
</tr>
<?php }?>
</tbody>
</table>