I have postgre sql database table in following format
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
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
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.