我想做的是将HTML表中的单元格分配给数据库中的特定记录。我正在用COLSPAN做一个表,所以每一行的列数都不相同。该表的代码是这样的:
<!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>
这将是查询
$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);
任何帮助都会很棒!谢谢
答案 0 :(得分:0)
请使用下面给出的代码向您显示表中的数据库数据
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>";
}
答案 1 :(得分:0)
您可以简单地获取结果,并为每个结果回显表格
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>
";
}