我正在尝试从HTML表格中的数据库生成列表,如下图所示;
https://i.stack.imgur.com/61XLl.png
这就是我的所作所为;
https://i.stack.imgur.com/lLsvF.png
代码;
<table cellpadding="3" border="1" style="width:100%;margin-top:30px; margin-bottom:50px; font-size:12px">
<thead>
<tr>
<th>KURSUS</th>
<th rowspan="2">NAMA PENSYARAH</th>
<th rowspan="2">NO. SIRI</th>
</tr>
<tr>
<th>NAMA</th>
</tr>
</thead>
<tbody align="center">
<?php
if($numrow>0)
{
while($row = $select->fetch_assoc()){
$code=explode("/",$row['po_code']);
$list=$connect->query("SELECT * FROM polist WHERE polist_poid='".$row['po_id']."' ORDER BY polist_bil ASC");
?>
<tr>
<td><?php echo $row['po_name']; ?></td>
<?php while($rowlist = $list->fetch_assoc()){
$name=$connect->query("SELECT * FROM user WHERE user_id='".$rowlist['polist_userid']."'");
$rowname=$name->fetch_array();?>
<td><?php echo $rowname['user_name']; ?></td>
<td><?php echo $code[0]."/PO/".$code[1]." - ".$rowlist['polist_bil']; ?></td>
<?php } ?>
</tr>
<?php
}
}
?>
</tbody>
</table>
帮帮我。提前谢谢你:)
答案 0 :(得分:1)
使用此代码。 Concat用户名和代码在第二个while循环中带有“br”标记,并在while循环后显示在“tds”中。
void DrawOverlay(String ping)
{
lbl_ping.setText(ping);
frame.getContentPane().validate(); // You modified child component lbl_ping (changed its size by setting a new text) so you need to recalculate all the child components
frame.getContentPane().repaint(); // Redraws the content pane and all of its children
}
答案 1 :(得分:0)
将<td>
放在<?php while($rowlist = $list->fetch_assoc()){
或者在开始显示html并将其存储在多维数组中之前获取所有数据。然后简单地遍历数据数组。这样你就不会拥有与HTML混合的php。