[英]Show data from database table in tabular format by using row and column index
I have postgre sql database table in following format 我有以下格式的PostgreSQL SQL数据库表
Row_no Col_no Name
1 1 Test
1 2 Result
1 3 Observation
2 1 abc
2 2 Result1
2 3 observation1
And I want to show data in html table in following format 我想以以下格式在html表中显示数据
Test Result Observation
abc Result1 observation1
So can any one suggest me how to do this? 那么有人可以建议我该怎么做吗?
Method : 方法 :
store them into output array by row and column index 按行和列索引将它们存储到输出数组中
like : 喜欢 :
$ARR_OUPUT[$row_no][$col_no] = $name;
Now you can print them into a html table 现在您可以将它们打印到html表中
like : 喜欢 :
echo '<table>'; foreach($ARR_OUTPUT as $key=>arr_temp) { echo '<tr>'; foreach($arr_temp as $name) { echo '<td>'.$name.'</td>'; } echo '</tr>'; } echo '<table>';
your array will be look like this 您的数组将如下所示
Array
(
[1] => Array
(
[1] => Test
[2] => Result
[3] => Observation
)
[2] => Array
(
[1] => abc
[2] => Result1
[3] => Observation1
)
)
Try below code 试试下面的代码
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.