donpvtzuux37724 2018-10-26 05:59
浏览 68
已采纳

将数据库中的信息显示在不同单元格的HTML表格中

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

  • 写回答

2条回答 默认 最新

  • dongmopu6734 2018-10-26 06:40
    关注

    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>
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。