PHP -不回显来自MySQL数据库的数据,但没有错误



PHP代码:

  • 注意:我确实使用了mysqli_connect()。

    $result = mysqli_query($con,"SELECT * FROM `smf_messages` WHERE `id_board` = 18");
    if(!$result) {
        echo "<center><p>Couldn't fetch news posts. Error code 2.</p></center>";
        mysqli_close($con);
    } else {
        $posts = array();
        $topicbdy = array();
        while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
        {
            $posts[$row['id_topic']] = $row['id_topic'];
            $topicbdy[$row['id_msg']] = $row['id_msg'];
        }
        $display = max($posts);
        $display2 = min($topicbdy);
        $qry = "SELECT * FROM `smf_messages` WHERE `id_board` = 18 AND `id_topic` = " . $display . " AND `id_msg` = " . $display2;
        $result2 = mysqli_query($con,$qry);
        //echo $qry;
        if(!$result2) {
            echo "<center><p>Couldn't fetch news posts. Error code 3.</p></center>";
        } else {
            while($show = mysqli_fetch_array($result,MYSQLI_ASSOC))
            {
                echo "<center><h1>" . $show['subject'] . "</h1></center><br /><br />";
                echo "<center>" . $show['body'] . "</center><br />";
            }
        }
        mysqli_free_result($result);
        mysqli_free_result($result2);
        mysqli_close($con);
    

它应该从数据库中获取我的基于smf的论坛的最新主题,从新闻板中获得最高的主题id,但最低的帖子id。它似乎正在做查询只是很好,因为我没有得到任何错误,但它不显示主题或主体。我该怎么办?

您的$result变量是错误的第二次查询获取。对于第二个查询

 while($show = mysqli_fetch_array($result,MYSQLI_ASSOC))
应该

 while($show = mysqli_fetch_array($result2,MYSQLI_ASSOC))
                                         ^

相关内容

  • 没有找到相关文章

最新更新