• <i id='TS6O5'><tr id='TS6O5'><dt id='TS6O5'><q id='TS6O5'><span id='TS6O5'><b id='TS6O5'><form id='TS6O5'><ins id='TS6O5'></ins><ul id='TS6O5'></ul><sub id='TS6O5'></sub></form><legend id='TS6O5'></legend><bdo id='TS6O5'><pre id='TS6O5'><center id='TS6O5'></center></pre></bdo></b><th id='TS6O5'></th></span></q></dt></tr></i><div id='TS6O5'><tfoot id='TS6O5'></tfoot><dl id='TS6O5'><fieldset id='TS6O5'></fieldset></dl></div>

        <bdo id='TS6O5'></bdo><ul id='TS6O5'></ul>
        <tfoot id='TS6O5'></tfoot>

        <small id='TS6O5'></small><noframes id='TS6O5'>

        <legend id='TS6O5'><style id='TS6O5'><dir id='TS6O5'><q id='TS6O5'></q></dir></style></legend>

      1. 如何使用 PDO PHP 创建分页

        时间:2023-10-05
        <tfoot id='QYCxd'></tfoot>
          <tbody id='QYCxd'></tbody>
        1. <legend id='QYCxd'><style id='QYCxd'><dir id='QYCxd'><q id='QYCxd'></q></dir></style></legend>

                <bdo id='QYCxd'></bdo><ul id='QYCxd'></ul>

                <i id='QYCxd'><tr id='QYCxd'><dt id='QYCxd'><q id='QYCxd'><span id='QYCxd'><b id='QYCxd'><form id='QYCxd'><ins id='QYCxd'></ins><ul id='QYCxd'></ul><sub id='QYCxd'></sub></form><legend id='QYCxd'></legend><bdo id='QYCxd'><pre id='QYCxd'><center id='QYCxd'></center></pre></bdo></b><th id='QYCxd'></th></span></q></dt></tr></i><div id='QYCxd'><tfoot id='QYCxd'></tfoot><dl id='QYCxd'><fieldset id='QYCxd'></fieldset></dl></div>

                  <small id='QYCxd'></small><noframes id='QYCxd'>

                  本文介绍了如何使用 PDO PHP 创建分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何使用 mysql pdo 和 php 创建分页我创建了这样的代码,但收到了一些错误消息

                  how to create pagination using mysql pdo and php im create code like this, but got some error msg

                  <?php 
                  $halaman = 2; //batasan halaman
                  $page = isset($_GET['halaman'])? (int)$_GET["halaman"]:1;
                  $mulai = ($page>1) ? ($page * $halaman) - $halaman : 0;
                  $result = $db->query("SELECT * FROM kategori");
                  $result->execute();
                  $total = $result->fetchAll();
                  $pages = ceil(count($total/$halaman)); 
                  $query = $db->prepare("SELECT * FROM kategori LIMIT $mulai, $halaman");
                      $query->execute();
                      $data = $query->fetchAll();
                      $no =$mulai+1;
                  ?>
                  <?php foreach ($data as $value): ?>
                  <tr>
                        <td><?php echo $no++; ?></td>                  
                        <td><?php echo $value['nama_kat']; ?></td> 
                  <?php               
                    endforeach;
                    ?>
                  

                  推荐答案

                  这是一个简单的分页方法:

                  Here is a simple approach to pagination:

                  <?php
                  $limit = 2;
                  $query = "SELECT count(*) FROM kategori";
                  
                  $s = $db->query($query);
                  $total_results = $s->fetchColumn();
                  $total_pages = ceil($total_results/$limit);
                  
                  if (!isset($_GET['page'])) {
                      $page = 1;
                  } else{
                      $page = $_GET['page'];
                  }
                  
                  
                  
                  $starting_limit = ($page-1)*$limit;
                  $show  = "SELECT * FROM kategori ORDER BY id DESC LIMIT ?,?";
                  
                  $r = $db->prepare($show);
                  $r->execute([$starting_limit, $limit]);
                  
                  while($res = $r->fetch(PDO::FETCH_ASSOC)):
                  ?>
                  <h4><?php echo $res['id'];?></h4>
                  <p><?php echo $res['nama_kat'];?></p>
                  <hr>
                  <?php
                  endwhile;
                  
                  
                  for ($page=1; $page <= $total_pages ; $page++):?>
                  
                  <a href='<?php echo "?page=$page"; ?>' class="links"><?php  echo $page; ?>
                   </a>
                  
                  <?php endfor; ?>
                  

                  这篇关于如何使用 PDO PHP 创建分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 PDO 语句中动态更改列名 下一篇:是否有必要关闭 PDO 连接

                  相关文章

                  最新文章

                  <i id='AoPyS'><tr id='AoPyS'><dt id='AoPyS'><q id='AoPyS'><span id='AoPyS'><b id='AoPyS'><form id='AoPyS'><ins id='AoPyS'></ins><ul id='AoPyS'></ul><sub id='AoPyS'></sub></form><legend id='AoPyS'></legend><bdo id='AoPyS'><pre id='AoPyS'><center id='AoPyS'></center></pre></bdo></b><th id='AoPyS'></th></span></q></dt></tr></i><div id='AoPyS'><tfoot id='AoPyS'></tfoot><dl id='AoPyS'><fieldset id='AoPyS'></fieldset></dl></div>

                      <bdo id='AoPyS'></bdo><ul id='AoPyS'></ul>
                    <tfoot id='AoPyS'></tfoot>
                    1. <legend id='AoPyS'><style id='AoPyS'><dir id='AoPyS'><q id='AoPyS'></q></dir></style></legend>

                      <small id='AoPyS'></small><noframes id='AoPyS'>