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

时间:2013-06-12 06:08:37

标签: php sql smf

所以我有这个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。它似乎做了很好的查询,因为我没有得到任何错误,但它没有显示主题或正文。我该怎么办?

1 个答案:

答案 0 :(得分:1)

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

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

应该是

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