用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2362|回复: 2
收起左侧

[已解决] 关于分页的问题

[复制链接]
发表于 2010-3-17 14:05:05 | 显示全部楼层 |阅读模式
books.php
class Books extends Controller {   
  function __construct() {   
    parent::Controller();   
    $this->load->helper('url');   
    $this->load->database();   
  }   
  
  function index() {   
    // load pagination class   
   $this->load->library('pagination');   
    $config['base_url'] = base_url().'index.php/books/index/';   
    $config['total_rows'] = $this->db->count_all('christian_books');   
    $config['per_page'] = '5';   
    $config['full_tag_open'] = '<p>';   
    $config['full_tag_close'] = '</p>';   
  
    $this->pagination->initialize($config);   
                  
    //load the model and get results   
    $this->load->model('books_model');   
    $data['results'] = $this->books_model->get_books($config['per_page'],$this->uri->segment(3));   
                  
    // load the HTML Table Class   
    $this->load->library('table');   
    $this->table->set_heading('ID', 'Title', 'Author', 'Description');   
                 
    // load the view   
    $this->load->view('books_view', $data);   
  }   
}  


books_model.php

class books_model extends Model {   
  function __construct(){   
   parent::Model();   
  }   
  
  function get_books($num, $offset) {   
    $query = $this->db->get('christian_books', $num, $offset);           
    return $query;   
  }   
}


books_view.php
<body>   
<h1>Christian Books</h1>   
<?php echo $this->table->generate($results); ?>   
<?php echo $this->pagination->create_links(); ?>   
</body>  
我用上面的例子去实现christian_books表里的数据分页显示,不过它把里面的东西全打印出来了,可是我只想显示里面的一个字段,例如字段title,我该怎么修改了
发表于 2010-3-17 14:42:25 | 显示全部楼层
$query = $this->db->select('title')->get('christian_books', $num, $offset);

评分

参与人数 1威望 +1 收起 理由
466141943a + 1 我很赞同

查看全部评分

 楼主| 发表于 2010-3-17 15:25:13 | 显示全部楼层
呵,谢谢哦

本版积分规则