因为我使用了两个表category(category_id, category_name)
第二个sub_category(sub_category_id, category_id, sub_category_title, sub_category_description, image, R_price, M_price, L_price, status)
。
我试图在category_id与sub_category表匹配时显示图像,价格和标题。
但它无法正常执行
模型
function getid($id)
{
$this->db->select('sub_category_id, category.category_name, sub_category_title, sub_category_description, image, R_price, M_price, L_price, status');
$this->db->from('sub_category,category');
// $this->db->join('category',' category.category_id = sub_category.category_id');
$this->db->where('sub_category.category_id = category.category_id');
$this->db->where('category.category_name = ',$id);
$qry1 = $this->db->get();
return $qry1->result_array();
}
控制器
public function product_grid()
{
$id= $this->input->post('dataid');
echo 'Data-Id is form controller: '.$id ;
$data['rs'] = $this->PizzaUp_User_model->getid($id);
$data['res'] = $this->PizzaUp_User_model->select('category');
$this->load->view('product_grid',$data);
}
答案 0 :(得分:0)
显示图片,价格,标题格式sub_category table.so这里不需要加入类别表
使用类别ID
获取子类别详细信息
function getid($id)
{
$this->db->select('sub_category_id,sub_category_title,sub_category_description, image, R_price, M_price, L_price, status');
$this->db->from('sub_category');
$this->db->where('sub_category.category_id',$id);
$qry1 = $this->db->get();
return $qry1->result_array();
}
答案 1 :(得分:0)
@Vidhi Patel请尝试简单加入,如果你不想迷惑自己,请使用小别名
function getid($id)
{
$this->db->select('sc.*, c.category_id');
$this->db->from('sub_category as sc');
$this->db->join('category as c','c.category_id = sc.category_id','LEFT');
$this->db->where('sc.category_id',$id);
$qry1 = $this->db->get();
if ($qry1->num_rows() > 0)
{
return $qry1->result_array();
}
return false;
}