只显示10条记录,然后一个按钮也显示所有记录

6ss1mwsb  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(342)

我想知道如何限制显示的记录,例如限制为10,然后他们需要一个按钮来获取所有的主题。我想知道怎么用那种方式展示它
功能代码:

public function get_topics(){
        $getTopic = $this->database->query("
        SELECT topics.*, klanten.foto, klanten.voornaam, boards.topic, ledenpagina.ledenpagina_id, klanten.achternaam FROM topics 
        LEFT JOIN ledenpagina ON ledenpagina.ledenpagina_id = topics.ledenpagina_id
        LEFT JOIN klanten ON topics.klant_id=klanten.id
        LEFT JOIN boards ON topics.board_id=boards.id
        WHERE ledenpagina.ledenpagina_id=:ledenpagina_id 
        ORDER BY id ASC");
        $this->database->bind(":ledenpagina_id", $_SESSION['ledenpagina_id']);    
        $topics = $this->database->resultset();

        return $topics;   
    }

php代码:

<section class="col-md-8 connectedSortable">
   <div class="clearfix paddingbottom10"></div>
    <div class="box box-info">
    <div class="panel panel-default">
      <div class="panel-heading main-color-bg">
         <h3 class="panel-title">Topics</h3>
      </div>
      div class="panel-body">
       <?php                      
       $toppic = $app->get_topics();
       foreach($toppic as $topic){

         echo '<a href="https://####/reactie"> <div id="topic">';
         echo '<div id="topicimg">';
         if(file_exists('assets/images/profielfotos/'.$topic['klant_id'])) { 
          echo '<img class="img-circle" src="/assets/images/profielfotos/'.$topic['klant_id'].'/'.$topic['foto'].'" />';
         } else {
            echo '<i class="fa fa-fw fa-user img-circle"></i>';
         }
         echo '</div><div id="topictekst">';
         echo '<b>'.$topic['topicnaam'].'</b>'; 
         echo ' - ' . $topic['voornaam'] . " " . $topic['achternaam'] ;
         echo '<span style="float:right; margin-top:15px; margin-left:5px;">'.implode($app->count_reactie($topic['id'])) .' reacties</span> <span style="float:right; color:lightgrey; margin-top:15px"class="fa fa-comment"></span>';
         echo '<hr><span class="badge bg-red">' . implode($app->boards($topic['board_id'])) . '</span>';
         echo ' laatste reactie: ' .$app->tijd_reactie($topic['id']) . ' door ' .$app->reactieDoor($topic['id']);
         echo '</div></div></a>';
        }
      ?>

   </div>
   </div>
/div><!-- /.box --> 
</section><!-- right col -->

这是我的第一个问题,所以请不要对我太苛刻

bjp0bcyl

bjp0bcyl1#

sql分页可以通过orderby子句的新特性实现,比如offset和fetchnext
下面是一个示例查询

SELECT * FROM TableName ORDER BY ID OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY

如果将偏移量计数参数化为(页码*页行计数),则可以为网页构建分页结构

相关问题