|
本帖最后由 wunayou 于 2012-2-21 12:00 编辑
这是模型
<?phpclass MHome extends CI_Model{ function __construct()
{ parent::__construct();
}
function get_category()
{ $query=$this->db->query('select * ,(select count(brand) from product where brand=product_brand.name) as product_count from product_brand;');
return $query->result(); }
}
?>
<?php
class Mbrand extends CI_Model{
function __construct()
{
parent::__construct();
}
var $id;
function get_product($id,$page)
{ $query=$this->db->query("select * from product where brand=(select name from product_brand where id=$id)limit 0,$page");
return $query->result(); }
function get_product_num($id)
{ $query=$this->db->query("select * from product where brand=(select name from product_brand where id=$id)");
return $query->num_rows();
}
}
?>
这是控制器
<?php
class Brand extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->database();
$this->load->model('Mhome');
$this->load->model('Mbrand');
$this->load->library('pagination');
}
function watches()
{
$config['base_url']=base_url().'brand/watches/'.$this->uri->segment(3);
$config['total_rows'] = $this->Mbrand->get_product_num($this->uri->segment(3));
$config['uri_segment'] = 4;
$config['per_page'] = 5; // 每页显示数量,为了能有更好的显示效果,我将该数值设置得较小
$config['num_links'] = 3; // 当前连接前后显示页码个数
$this->pagination->initialize($config);
$data['category']=$this->Mhome->get_category();
$data['brand']=$this->Mbrand->get_product($this->uri->segment(3),$config['per_page']);
$this->load->view('header',$data);
$this->load->view('brand');
$this->load->view('footer');
}
}
?>
代码都在这里 为什么打开网页就好像是12M网速变成1M还恐怖
|
|