【发布时间】:2016-01-26 23:46:50
【问题描述】:
大家好,我是一个新的 codeigniter,我对 codeigniter 中的分页有问题我尝试在 google youtube codeigniter 文档和其他网站上搜索,我跟随但我不能 我的代码中的问题在于我的 $limit I limt 1 它显示 3 burger 当我点击链接分页错误时说 404 Page Not Found 谁能帮助我: 我的数据库表:
product:
id title image category
1 a a.jpg burger
2 b b.jpg burger
3 c c.jpg burger
4 d d.jpg piza
5 e e.jpg piza
6 f f.jpg piza
我想要按汉堡分类的结果分页,按披萨分页披萨
我的型号代码:
<?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;
}
}
控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('product_model','product');
}
public function menu()
{
$data = array();
$data['sides'] = $this->product->get_product('sides');
$total_sides = $this->product->get_total('sides');
$limit_sides = 1;
$link_sides = 'http://localhost/mbl/burger';
$data['pagination_sides'] = $this->pagination($total_sides,$limit_sides,$link_sides);
$data['beverages'] = $this->product->get_product('beverages');
$total_beverages = $this->product->get_total('beverages');
$limit_beverages = 1;
$id = $this->uri->segment(3);
$link_beverages = 'http://localhost/mbl/beverages';
$data['pagination_beverages'] = $this->pagination($total_beverages,$limit_beverages,$link_beverages);
$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();
}
我的看法:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Pizza</h1>
<ul>
<?php foreach($pizza as $val) { ?>
<li><?php echo $val->title; ?></li>
<?php } ?>
</ul>
<?php echo $pagination_pizza; ?>
<hr>
<h1>Burger</h1>
<ul>
<?php foreach($burger as $val) { ?>
<li><?php echo $val->title; ?></li>
<?php } ?>
</ul>
<?php echo $pagination_burger; ?>
</body>
</html>
谁能帮助我或编辑我的代码并为我准备一个新代码:( :(
【问题讨论】:
-
究竟是什么,没有按预期工作??
-
错误的链接和很多。请帮助我,我非常需要帮助
-
你应该添加你得到什么样的错误链接,你还有什么其他问题?不要指望任何人只是猜测你的问题。或者,如果他这样做,那可能不是您的实际问题。
-
好的,我会编辑更多。但是你能帮我吗?我非常需要帮助
标签: php codeigniter pagination codeigniter-2 codeigniter-3