greedefoxes 发表于 2015-5-12 17:06:48

附上 返回第一页的错误信息 :L

Closer 发表于 2015-5-12 17:22:20

看有沒有幫助你
CI 社區 - GET传参分页使用

如果沒辦法就慢慢找了... Google - 分頁

 

greedefoxes 发表于 2015-5-14 14:46:09

    原来CI分页是这样套用bootstrap的样式的 :   $config['full_tag_open'] = '<ul class="pagination">';
   $config['full_tag_close'] = '</ul>';
参看帖子地址:http://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=18687&extra=page%3D3

    之前的那个Database error :limit后面一个参数为空,是因为我没有设置默认值。
嘿嘿,参看帖子地址:http://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=10579





greedefoxes 发表于 2015-5-14 17:05:11

本帖最后由 greedefoxes 于 2015-5-14 17:16 编辑

{:soso_e121:}终于实现了我想要的结果,在此感谢版主Closer的帮助。总结一下:简单地实现动态分页,我学习了使用CI类库参考中的分页类和HTML表格类。
分页类: 1) $this->load->library('pagination'); 2)$config['base_url'] 、$config['total_rows']、$config['per_page']等根据需要进行初始化。
3)接触了 $this->uri->segment ( 3 )的使用,可以获得url上的参数值,从index.php后面开始数第三个'/'后面的参数。
表格类:
1) $this->load->library('table');//在控制器中使用$this->load->library 函数来初始化表格类,建立一个表格库对象的实例: $this->table.
2) $this->table->set_heading('Name', 'Color', 'Size');//设置表格标题栏
3) $query = $this->db->query("SELECT * FROM my_table");   $this->table->generate( $query);//由数据库查询结果生成表格
4) $this->table->set_template($tmpl);//设置表格样式

参阅   分页类      表格类







tokyo2006 发表于 2015-5-18 15:15:55

本帖最后由 tokyo2006 于 2015-5-18 15:18 编辑

我来贴一个我自己写的Page类吧
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

class Page {

    var $page_size = DEFAULT_PAGE_SIZE;
    var $start = DEFAULT_PAGE_START;
    var $total_count;
    var $result;
    var $to_string='this is page object';

    function __construct() {

    }

    public function init($start, $total_count, $page_size, $result)
    {
      $this->page_size = $page_size;
      $this->result = $result;
      $this->total_count = $total_count;
      $this->start = $start;
      return $this;
    }
    /**
   * 取总记录数.
   */
    public function getTotalCount() {
      return $this->total_count;
    }

    /**
   * 取总页数.
   */
    public function getTotalPageCount() {
      if ($this->total_count % $this->page_size == 0)
            return intval($this->total_count / $this->page_size);
      else
            return intval($this->total_count / $this->page_size + 1);
    }

    /**
   * 取每页数据容量.
   */
    public function getPageSize() {
      return $this->page_size;
    }

    /**
   * 取当前页中的记录.
   */
    public function getResult() {
      return $this->result;
    }

    /**
   * 取该页当前页码,页码从1开始.
   */
    public function getCurrentPageNo() {
      return intval($this->start / $this->page_size + 1);
    }

    /**
   * 该页是否有下一页.
   */
    public function hasNextPage() {

      return ($this->getCurrentPageNo() < $this->getTotalPageCount());
    }

    /**
   * 该页是否有上一页.
   */
    public function hasPreviousPage() {
      return $this->getCurrentPageNo() > 1;
    }

}

?>

使用的时候你可以先载入这个类然后使用它,请确保在autoload.php中载入了这个类,下面是一个使用page的方法
/**   * search area list for page
   * @param type $name
   * @param type $headName
   * @param type $currentPostion
   * @param type $limit
   * @param type $orderName
   * @param type $asc
   * @return type
   */
    public function getAreaList($name, $headName, $currentPage, $limit, $orderName, $asc) {
      $currentPostion = ($currentPage-1)*$limit;

      $select = 'select id,name,depth,headName,parentId ';
      $from = ' from tour_area';
      $where = ' where 1=1';
      if ($headName != '') {
            $where = $where . ' and headName='.$headName;
      }
      if ($name != '') {
            $where = $where . ' and name like '.'\'%'.$name.'%\'';
      }
      if ($asc) {
            $where = $where . ' order by ' . ' ' . $orderName . ' asc';
      } else {
            $where = $where . ' order by ' . ' ' . $orderName . ' desc';
      }
      $total_count = $this->db->query('select count(0) as cnt '.$from.$where)->row()->cnt;
      $where = $where . ' limit ' . $currentPostion . ',' . $limit;
      $result = $this->db->query($select.$from.$where)->result();
      $page = new Page();

      $page->init($currentPostion, $total_count, $limit,$result);
      return $page;
    }
虽然我的实现方法可能有些笨拙,但是基本上可以满足我的开发需求

greedefoxes 发表于 2015-5-19 15:02:45

tokyo2006 发表于 2015-5-18 15:15
我来贴一个我自己写的Page类吧




    能够写出自己独特的方法,是很聪明的人。
页: 1 [2]
查看完整版本: 请问 动态数据库 读取出的表格 进行分页 如何实现?MVC结构