2011-08-19 123 views
0

我想在config文件夹中创建一个分页文件以用于许多页面。帮助我在配置文件中创建分页文件

但是,我不知道如何设置$ config []的值,因为它们属于数据。

例如:$ config ['total_rows'] =? $ config ['base_url'] =?

please..help me!谢谢 !

+0

你要查询数据库,你弥补之前得到总行值你的配置设置。基地网址是您的网页url – Brad

回答

1
$this->load->library('pagination'); 
    $this->load->library('table'); 

    $config['base_url'] = base_url().'/site/big/'; 
    $where = "bot = '2' OR bot = '0'"; 
    $this->db->where($where); 
    $config['total_rows'] = $this->db->count_all_results('visitors');//query here for total rows 
    $config['per_page'] = 15; 
    //$config['num_links'] = 20; 
    $config['full_tag_open'] = '<div id="pagination">'; 
    $config['full_tag_close'] = '</div>'; 

    $this->pagination->initialize($config); 

$this->db->order_by('date', 'DESC'); 
    $where = "bot = '2' OR bot = '0'"; 
    $this->db->where($where); 
    $this->db->select('id, ip, date, page, host, agent, spammer, country, total, refer'); 
    $data['records'] = $this->db->get('visitors', $config['per_page'], $this->uri->segment(3)); 
    $this->table->set_heading('Id', 'IP', 'Date', 'Page', 'Host', 'Agent', 'Spam', 'Country', 'Total', 'Referer'); 
    $this->load->view('site_view', $data); 

基本URL是您网站的网址+控制器/功能 每页是你想要多少行看到每个网页上

+0

感谢您的回复!但是......'游客'是桌子?如何将动态值发送到$ where变量?你的代码不能用于许多带有数据表的页面:( – misakitran

+0

)是的,访问者是表格,动态值将来自表单,搜索或其他内容,或者像我的显式定义的那样是$ where =“bot ='2'OR bot ='0'“;这个脚本适用于我网站上的26个页面,我添加了控制器的其余部分供您查看 – Brad