douzongluo7542 2015-10-27 06:56
浏览 59

如何显示产品类别codeigniter的分页?

Hi all I am a new of codeigniter I have problam with pagination on codeigniter I try to search google and youtube but I can not do it who can help me please this my code model:

<?php
class Product_model extends CI_Model {


    function get_product($category="") {
        $this->db->select('*');
        $this->db->from('product');

        if($category) {
            $this->db->where('category',$category);
        }

        $query = $this->db->get();
        return $query->result();
    }


    function get_total($category="") {
        $this->db->select('count(*) AS num_row');
        $this->db->from('product');

        if($category) {
            $this->db->where('category',$category);
        }
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->row()->num_row;
    }

}

and this my controoler code:

public function __construct()
    {
        parent::__construct();
        $this->load->model('product_model','product');
    }
public function menu()
    {
        $data = array();

        $data['burger'] = $this->product->get_product('burger');
        $total_burger = $this->product->get_total('burger');
        $limit_burger = 1;
        $link_burger = 'http://localhost/mbl/site/menu/burger';
        $data['pagination_burger'] = $this->pagination($total_burger,$limit_burger,$link_burger);

        $this->load->view('header_view');
        $this->load->view('nav_view');
        $this->load->view('content_view');
        $this->load->view('content_left_view',$data);
        $this->load->view('content_right_view');
        $this->load->view('footer_view');

    }



    private function pagination($total ,$per_page ,$link) {

        $config['base_url'] = $link;
        $config['total_rows'] = $total;
        $config['per_page'] = $per_page;
        $config['page_query_string'] = TRUE;

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

        return $this->pagination->create_links();
    }

and my view:

<h1>Burger</h1>
<ul>
    <?php foreach($burger as $val) { ?>
        <li><?php echo $val->title; ?></li>
    <?php } ?>
</ul>

<?php echo $pagination_burger; ?>
  • 写回答

1条回答 默认 最新

  • douqingji3026 2015-10-27 07:08
    关注

    In Codigniter it is very simple

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

    load this library

    $config['base_url'] = 'http://example.com/index.php/test/page/';
    $config['total_rows'] = 200;
    $config['per_page'] = 20; 
    
    $this->pagination->initialize($config); 
    
    echo $this->pagination->create_links(); 
    

    or

    check this url

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么