我想测试的每个循环都有一个小循环。但它只显示了两个空列表项。我还在phpmyadmin中测试了SQL,它返回了一个正确的表。我想显示表中的标题,但正如我所说,我得到两个空列表项。
有人知道我做错了什么吗?

<?
    //  content
    $content            = "SELECT * FROM `snm_content` WHERE catid = 13";
    $contentcon         = $conn->query($content);
    $contentcr          = array();
    while ($contentcr[] = $contentcon->fetch_array());


    foreach($contentcr as $content)
    {
        $contentje .= '<li>'.$contentcr['title'].'</li>';
    }
    echo $contentje;
?>

最佳答案

在foreach循环内用$contentcr替换$content

<?
    //  content
    $content            = "SELECT * FROM `snm_content` WHERE catid = 13";
    $contentcon         = $conn->query($content);
    $contentcr          = array();
    while ($contentcr[] = $contentcon->fetch_array());


    foreach($contentcr as $content)
    {
        $contentje .= '<li>'.$content['title'].'</li>'; // Here
    }
    echo $contentje;
?>

09-20 11:18