• 文档地址

  • 数据分页

    <?php
     $db = new Medoo([
                  'database_type' => 'mysql',
                  'database_name' => 'pchome_admin',
                  'server' => '172.19.198.255',
                  'username' => 'root',
                  'password' => 'yxdown@10086',
                  'charset' => 'utf8mb4',
                  'collation' => 'utf8mb4_general_ci',
                  'port' => 3306
              ]);
      $page   = isset($_GET['page'])  ? $_GET['page']  : 1;
      $limit  = isset($_GET['limit']) ? min($_GET['limit'], 50) : 20;
      $offset = ($page - 1) * $limit;
      $count  = $db->count($table)
      //带条件的查询
      //$count  = $db->count($table, $where);
      /**
       * table [string]            表名
       * join [array]              多表查询
       * column [string]           需要统计的字段.
       * where (optional) [array]  WHERE 条件.
       */
      //$count  = $db->count($table, $join, $column, $where);                    //总条数
        $id = $this->db->select($table ,"id", ["LIMIT" => [$offset , $limit]]);  //id集合
        $list = $this->db->select($table, "*", ["id" => $id]);                   //请求数据库数据
        $totalPage = ceil($count/$limit);                                        //总页数                          
    ?>
Last modification:December 18, 2020
如果觉得我的文章对你有用,请随意赞赏