gpt4 book ai didi

PHP HTML 表格在一个 标签中检索多个数据

转载 作者:行者123 更新时间:2023-11-28 23:14:39 25 4
gpt4 key购买 nike

我正在尝试从 HTML 表格中的数据库生成列表,如下图所示;

/image/61XLl.png

这就是我所做的;

/image/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>

帮帮我。提前谢谢你:)

最佳答案

使用此代码。在第二个 while 循环中将用户名和代码与“br”标签连接起来,并在 while 循环后显示在“tds”中。

<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
$user_names = $codes = ''; // define empty variables
while($rowlist = $list->fetch_assoc()){

$name=$connect->query("SELECT * FROM user WHERE user_id='".$rowlist['polist_userid']."'");
$rowname=$name->fetch_array();
$user_names .= $rowname['user_name']."<br/>"; //concat to a single string
$codes .= $code[0]."/PO/".$code[1]." - ".$rowlist['polist_bil']."<br/>"; //concat to a single string
}?>
<td><?php echo $user_names;?></td>
<td><?php echo $codes;?></td>
</tr>

<?php
}
}
?>
</tbody>

关于PHP HTML 表格在一个 <td> 标签中检索多个数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44420327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com