What I am trying to do is to assign a cell from my HTML table to a specific record from my database. I am doing a table with COLSPAN, so it is not the same number of columns in every row. The code for the table is something like this:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<td colspan="4">TITLE
</td>
</tr>
<tr>
<td colspan="2">tag1</td>
<td colspan="2">info from database</td>
</tr>
<tr>
<td >tag2</td>
<td>info from database</td>
<td>tag3</td>
<td>info from database</td>
</tr>
</tbody>
</table>
</body>
</html>
This would be the query
$con = new mysqli($servername, $username, $password, $database);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$sql = "SELECT * FROM table WHERE id=id ";
$result = $con->query($sql);
Any help would be great! Thanks
You can simply fetch your results and for every result you echo your table out
while($row = mysqli_fetch_assoc($result)) {
echo "
<tr>
<td colspan='4'>TITLE
</td>
</tr>
<tr>
<td colspan='2'>tag1</td>
<td colspan='2'>".$row['NAME OF THE ROW']."</td>
</tr>
<tr>
<td >tag2</td>
<td>".$row['NAME OF THE ROW']."</td>
<td>tag3</td>
<td>".$row['NAME OF THE ROW']."</td>
</tr>
";
}
Please use the given below code to show you db data in table
while($result = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$res['name']."</td>";
echo "<td>".$res['age']."</td>";
echo "<td>".$res['email']."</td>";
echo "<tr>";
}