【发布时间】:2018-07-27 17:30:32
【问题描述】:
我想加入三个表并从函数中获取数据但无法这样做。我可以获取类别联合数据,但不能获取产品线数据。
我有三张桌子。一个是cv_products,第二个是cv_category,最后一个是product_line。我在cv_products 中有一个名为product_line 的表字段。
这是我在模型中的功能
public function get_products($id = 0, $slug = FALSE){
if($id === 0 && $slug === FALSE){
$this->db->order_by('cv_products.id', 'DESC');
$this->db->select('cv_products.*, cv_category.name as categoryname', 'product_line.name as linename','cv_category.id as category_id' );
$this->db->join('cv_category','cv_category.id = cv_products.category', 'left');
$this->db->join('product_line','product_line.id = cv_products.product_line', 'left');
$query= $this->db->get('cv_products');
return $query->result_array();
}
$this->db->select('cv_products.*, cv_category.name as categoryname', 'product_line.name as linename','cv_category.id as category_id' );
$this->db->join('cv_category','cv_category.id = cv_products.category', 'left');
$this->db->join('product_line','product_line.id = cv_products.product_line', 'left');
$query= $this->db->get_where('cv_products', array('cv_products.id' => $id, 'slug' => $slug));
return $query->row_array();
}
鉴于它给出了一个错误,如
Severity: Notice
Message: Undefined index: linename.
因为我在cv_products、cv_category 和product_line 中都有一个字段name,所以在选择时我已经给出了product_line.name as linename。 cv_category 关节没问题,但在product_line 关节时间的情况下无法获得相同的结果。
【问题讨论】:
标签: php codeigniter mysqli jointable