我在数据库中有两个表 ::: 1. tbl_category 2. tbl_product。在主页中显示所有类别列表,当用户单击signle类别时,它会按类别ID(在tbl_product中包含类别ID)进入产品页面(来自tbl_product)
问题 ::: 我想在此处显示类别名称和图像。这样用户就可以看到他们点击了哪个类别(来自 tbl_category ) ::: 我怎样才能得到它们???请帮我
控制器 ::::
class Home extends CI_Controller{
//put your code here
public function __construct() {
parent::__construct();
$this->load->model('home_model');
}
public function index(){
$data=array();
$data['result']=$this->home_model->selectCategory($config['per_page'], $this->uri->segment(3));
$data['maincontent']=$this->load->view('home_message',$data,TRUE);
$this->load->view('home', $data);
}
public function category($category_id){
$data=array();
$data['result']=$this->home_model->selectProductByCategoryId($category_id);
$data['maincontent']=$this->load->view('category_detail',$data,TRUE);
$this->load->view('home', $data);
}
模型::::
class Home_Model extends CI_Model{
//put your code here
public function selectCategory($per_page, $offset)
{
$this->db->select('*');
$this->db->from('tbl_category');
$this->db->order_by("category_id", "desc");
$query = $this->db->get('', $per_page, $offset);
foreach ($query->result() as $row)
$data[] = $row;
return $data;
}
public function selectProductByCategoryId($category_id)
{
$this->db->select('*');
$this->db->from('tbl_product');
$this->db->where('category_id',$category_id);
//$this->db->order_by("product_id", "desc");
$query_result= $this->db->get();
$result=$query_result->result();
return $result;
}
看法::::
我想在此处显示类别名称和图像。这样用户就可以看到他们点击了哪个类别 ::::
<?php
foreach ($result as $values)
{
?>
<div>
<div>
<a href="<?php echo base_url(); ?>product_category/product_detail/<?php echo $values->product_id ?>"><img src="<?php echo base_url();?><?php echo $values->product_image ?>" width="90%" height="220" /></a>
</div>
<div>
<b><a href="<?php echo base_url(); ?>product_category/product_detail/<?php echo $values->product_id ?>"><?php echo $values->product_name ?></a></b> <br>
<b>Price: <?php echo $values->product_price ?></b> <br>
<a href="<?php echo base_url(); ?>product_category/product_detail/<?php echo $values->product_id ?>" class="a-btn">Order Now</a>
</div>
</div>
<?php } ?>