php 而循环不显示 15 行之后的行

你好,我有两个文件,一个文件包含主要帖子,第二个文件包含加载更多帖子代码


以下是主文件的代码,但在这个文件中,我有一个问题,我必须循环php中的所有mysql行,我可以使用while循环来做到这一点,但是当我尝试这样做时,我会得到所有行,但在15行之后,它只显示那些在15行之后的行,比如只有16行


我的主要.php代码


while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

    $nv_name_split = str_replace('_', ' ', $row['novel_name']);

    echo '<br><a href="episode?novel='.$row['novel_name'].'&episode='.$row['episode_num'].'"><figure class="snip1253"><div class="image"><img width="100%"src="images/sneakpeaks/'.$row['sneak_peak'].'" alt="sample59"/></div><figcaption>'.

            '<div class="date"><span class="day">'.$row['day'].'</span><span class="month">'.$row['month'].'</span></div><h3>Episode # '.$row['episode_num'].'</h3>  <footer>

            <div class="writer text-center"><i class="fa fa-book"> '.$nv_name_split.'</i></div>

            <div class="love"><i class="fa fa-thumbs-up"></i>'.$row['likes'].'</div>

            <div class="comments"><i class="fa fa-comments"></i>'.$row['comments'].'</div></footer></figure></a></figcaption><br><br>';

}

?>

<?php 

$stmt_count = $novel_list->runQuery("SELECT episode_num 

                                    FROM posts 

                                    WHERE just_skpk='0'");

$stmt_count->execute();

while ($rows = $stmt_count->fetch(PDO::FETCH_ASSOC)) {

    $count_row = $rows['episode_num'];

}

if ($limit < $count_row) {

    echo'<form id="frm_more_post">

            <center>

            <button type="submit" class="form-control btn btn-load_more" id="frm_btn_more">Load More Posts</button>

            </center>

        </form>

        <br>

        <br>';

}else{

    echo'<form id="frm_more_post">

            <center>

            <button type="submit" disabled class="disabled form-control btn btn-load_more" id="frm_btn_more">No More Posts</button>

            </center>

            </form>

            <br>

            <br>'; 

}

这是我load_more.php代码,我使用ajax发布帖子限制


猛跑小猪
浏览 86回答 2
2回答

慕田峪4524236

在你的代码中,你得到episode_num为$count_row,但它应该是没有行。试试下面的代码$novel_list = new USER();if (isset($_POST['page'])) {&nbsp; &nbsp;&nbsp; &nbsp; $limit = $_POST['page']+3;&nbsp; &nbsp; $stmt = $novel_list->runQuery("SELECT *&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM posts&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE just_skpk='0'&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ORDER BY id DESC&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LIMIT $limit");&nbsp; &nbsp; $stmt->execute();&nbsp; &nbsp; if ($stmt->rowCount(0)) {&nbsp; &nbsp; &nbsp; &nbsp; echo '<input class="hidden" id="pages" value="'.$limit.'"/>';&nbsp; &nbsp; &nbsp; &nbsp; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $nv_name_split = str_replace('_', ' ', $row['novel_name']);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<br><a data-pages="'.$limit.'" href="episode?novel='.$row['novel_name'].'&episode='.$row['episode_num'].'"><figure class="snip1253"><div class="image"><img width="100%"src="images/sneakpeaks/'.$row['sneak_peak'].'" alt="sample59"/></div><figcaption>'.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<div class="date"><span class="day">'.$row['day'].'</span><span class="month">'.$row['month'].'</span></div><h3>Episode # '.$row['episode_num'].'</h3>&nbsp; <footer>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="writer text-center"><i class="fa fa-book"> '.$nv_name_split.'</i></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="love"><i class="fa fa-thumbs-up"></i>'.$row['likes'].'</div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="comments"><i class="fa fa-comments"></i>'.$row['comments'].'</div></footer></figure></a></figcaption><br><br>';&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; $stmt_count = $novel_list->runQuery("SELECT count(*) as cnt&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM posts&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE just_skpk='0'");&nbsp; &nbsp; &nbsp; &nbsp; $stmt_count->execute();&nbsp; &nbsp; &nbsp; &nbsp; while ($rows = $stmt_count->fetch(PDO::FETCH_ASSOC)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $count_row = $rows['cnt'];&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; if ($limit < $count_row) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<form id="frm_more_post">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <center>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button type="submit" class="form-control btn btn-load_more" id="frm_btn_more">Load More Posts</button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</center>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </form>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>';&nbsp; &nbsp; &nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<form id="frm_more_post">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <center>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button type="submit" disabled class="disabled form-control btn btn-load_more" id="frm_btn_more">No More Posts</button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </center>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</form>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>';&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; echo 0 ;&nbsp; &nbsp; }}

慕无忌1623718

我认为这是因为分页。在文件load_more.php中,您正在设置限制$limit&nbsp;=&nbsp;$_POST['page']+3;并在文件中,主.phpif&nbsp;($limit&nbsp;<&nbsp;$count_row)这是检查。
打开App,查看更多内容
随时随地看视频慕课网APP