有谁能帮我把下面的每一行放到不同的html表中吗。
所以每行一个表,而不是整个数据库只有一个表?
最好通过int-id调用并以这种方式填充?
我有一个数据库“dorav3”,表名为“dtab1”,下面有列
+---------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------+------+-----+---------+----------------+
| Pillar | text | YES | | NULL | |
| PD Team | text | YES | | NULL | |
| PD Team ID | text | YES | | NULL | |
| PD Team URL | text | YES | | NULL | |
| Summary | text | YES | | NULL | |
| PD Service | text | YES | | NULL | |
| PD Service ID | text | YES | | NULL | |
| Outlook DL | text | YES | | NULL | |
| Outlook Email | text | YES | | NULL | |
| Description | text | YES | | NULL | |
| Tags | text | YES | | NULL | |
| PD EP ID | text | YES | | NULL | |
| PD EP URL | text | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | auto_increment |
+---------------+---------+------+-----+---------+----------------+
我可以连接到和填充html从这个与下面。
PHP
<?php
// php populate html table from mysql database
$hostname = "localhost";
$username = "xxxx";
$password = "xxxx";
$databaseName = "dorav3";
// connect to mysql
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
// mysql select query
$query = "SELECT * FROM `dtab1";
$result1 = mysqli_query($connect, $query);
$dataRow = "";
while($row2 = mysqli_fetch_array($result2))
{
$dataRow = $dataRow."<tr><td>$row2[0]</td><td>$row2[1]</td><td>$row2[2]</td><td>$row2[3]</td><td>$row2[4]</td><td>$row2[5]</td><td>$row2[6]</td><td>$row2[7]</td><td>$row2[8]</td><td>$row2[9]</td><td>$row2[10]</td><td>$row2[11]</td><td>$row2[12]</td></tr>";
}
?>
html格式
<title>PHP DATA ROW TABLE FROM DATABASE</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
table,th,tr,td
{
border: 1px solid black;
}
</style>
<table>
<tr>
<th>Pillar</th>
<th>PD Team</th>
<th>PD Team ID</th>
<th>PD Team URL</th>
<th>Summary</th>
<th>PD Service</th>
<th>PD Service ID</th>
<th>Outlook DL</th>
<th>Outlook Email</th>
<th>Description</th>
<th>Tags</th>
<th>PD EP ID</th>
<th>PD EP URL</th>
</tr>
<?php while($row1 = mysqli_fetch_array($result1)):;?>
<tr>
<td><?php echo $row1[0];?></td>
<td><?php echo $row1[1];?></td>
<td><?php echo $row1[2];?></td>
<td><?php echo $row1[3];?></td>
<td><?php echo $row1[4];?></td>
<td><?php echo $row1[5];?></td>
<td><?php echo $row1[6];?></td>
<td><?php echo $row1[7];?></td>
<td><?php echo $row1[8];?></td>
<td><?php echo $row1[9];?></td>
<td><?php echo $row1[10];?></td>
<td><?php echo $row1[11];?></td>
<td><?php echo $row1[12];?></td>
</tr>
<?php endwhile;?>
</table>
1条答案
按热度按时间qgelzfjb1#
应该将while放在table标记之前,将endwhile标记放在closing table标记之后。