0

所以我有这个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);
    

它应该通过获取最高的主题 ID,但最低的帖子 ID,从新闻板上为我的基于 SMF 的论坛从数据库中获取最新主题。查询似乎很好,因为我没有收到任何错误,但它没有显示主题或正文。我应该怎么办?

4

1 回答 1

1

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

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

应该

 while($show = mysqli_fetch_array($result2,MYSQLI_ASSOC))
                                         ^
于 2013-06-12T06:17:06.963 回答