I have an array value in the database like the table below, I want to try to sort the data based on the value of the value of field A to be the column and field B as the value of column A, but I cannot parse it
NO| field_A |field_B
---------------------------
1 | username | brian
1 | email | [email protected]
1 | date_birth | 1996-06-09
1 | place_birth | Chichago
2 | username | adams
2 | email | [email protected]
2 | date_birth | 1990-07-11
2 | place_birth | Manhattan
3 | username | john
3 | email | [email protected]
3 | date_birth | 1988-10-02
3 | place_birth | Miami
I expected
No | Username | Email | Date Birth | Place Birth |
-------------------------------------------------------------------------
1 | brian | [email protected] | 1996-06-09 | Chichago |
2 | adams | [email protected] | 1990-07-11 | Manhattan |
3 | john | [email protected] | 1988-10-02 | Miami |
myscript
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>NO</th>
<th>Username </th>
<th>Email </th>
<th>Date Birth</th>
<th>Place Birth</th>
</tr>
</thead>
<tbody>
<?php
$q = mysqli_query($server, "SELECT * FROM my_tabel ") or die ($server->error);
$result = array();
while ($row = mysqli_fetch_array($q)) {
$result[] = $row;
}
foreach($result as $key => $rowx) {
echo "<tr>";
echo "<td>" .$rowx['username']. "</td>" ;
echo "<td>" .$rowx['email']. "</td>";
echo "<td>" .$rowx['date_birth']. "</td>";
echo "<td>" .$rowx['place_birth']. "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
JOIN? Make sure that the table you are joining in only has 1 possible result.