Mysqli查询返回一个未知的额外记录,其中包含实际结果

时间:2018-05-15 16:53:08

标签: php mysqli

我正在查询它正在提取的记录,但它显示的是一个奇怪的empty record,这在数据库中甚至都不常见。

额外记录表示列表中有一个额外的空<li>。 $ dba是数据库连接。

$dba=mysqli_connect('127.0.0.1','root','','store');

foreach无效。

请帮忙解决。

<?php include ('inc/db.php');
$zmcats     = "select i.ename as iname,c.ename as cname, c.id as cid
from items i
inner join categories c on c.id = i.cat_id
where i.view > 4
and c.id = i.cat_id
and c.status = 1
group by c.id
";
$zmcat      = $dba->query($zmcats);
//$zzmcat       = array();
while ($zzmcat[] = $zmcat->fetch_array(MYSQLI_ASSOC)){}
foreach ($zzmcat as $zcatzn) {
?>
<li class="category-list list-parent"><a href="#"><?php echo $zcatzn["cname"]; ?></a>
    <ul class="list-child">
    <?php
    $q  = "SELECT id, ename FROM items 
    WHERE view > 4 and status = 1 and cat_id='".$zcatzn['cid']."' ";
    $qq = $dba->query($q);
    while ($product = $qq->fetch_array(MYSQLI_ASSOC)) {
    ?>
        <li class="category-list"><a href="#">
        <?php echo $product['ename']; ?>
        </a></li>
    <?php } ?>
    </ul>
</li>
<?php } ?>

enter image description here

1 个答案:

答案 0 :(得分:1)

while循环之后的foreach循环是不必要的,只需使用简单的while循环

x,y