gpt4 book ai didi

php - HTML 表格不显示 php while 在其中循环

转载 作者:太空宇宙 更新时间:2023-11-04 12:03:10 26 4
gpt4 key购买 nike

我正在创建一个循环来 self 的数据库的信息的表。我用 html 创建了表格,并通过外部 css 表添加了样式。表格格式不以任何方式显示。没有显示任何边框,并且 100% 宽度不起作用。我的 while 循环会导致这种影响吗?

<table class="tableproduct">
<tr>
<th class="thproduct">Product ID</th>
<th class="thproduct">Product Name</th>
<th class="thproduct">Price</th>
<th class="thproduct">Category</th>
<th class="thproduct">Description</th>
</tr>
<?php
while($row = mysqli_fetch_assoc($q)) : ?>

<tr>
<td class="tdproduct"><?php echo $row['product_id']; ?> </td>
<td class="tdproduct"><?php echo $row['name']; ?> </td>
<td class="tdproduct"><?php echo $row['price']; ?> </td>
<td class="tdproduct"><?php echo $row['category']; ?> </td>
<td class="tdproduct"><?php echo $row['description']; ?> </td>
</tr>
</table>
<?php endwhile; ?>


.tableproduct {
width: 100%;
border: 1px solid black;
}
.tdproduct {
border: 1px solid black;
}
.thproduct {
height: 100px;
border: 1px solid black;
}

最佳答案

我最终解决了这个问题。

我必须在 while 循环中放置一个 if 语句,它创建了我正在寻找的结果。

我将其添加到 while 循环中:

if( $result ){  
while($row = mysqli_fetch_assoc($result)) :

关于php - HTML 表格不显示 php while 在其中循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29586926/

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