在Codeigniter中将4个具有公共字段的表连接起来

时间:2018-06-23 17:09:44

标签: mysql sql codeigniter

我有四个表,分别名为tblproducts,tblprospecification,tblcomspecification和tblledtvpecification。

  • tblproducts的字段为proid,product_code,product_name, pro_img,pro_resize_img,pro_thumb_img及其存储产品 详细信息。

  • 第二个表是tblprospecification,它存储移动设备规范,它具有列speid,proid,in_the_box,model_number,model_name,color,browse_type,sim_type。

  • 第三张表是用于存储计算机规范的tblcomspecification,其列为comspecificid,proid,型号名称,颜色,系列等。第四列是istblledtvpecification,用于存储ledtv规范,其列为tvspecificid,型号名,dsize,stype_id,hd_techno。

我正在使用下面的查询输入

$query= $this->db->select( 'tblproducts.proid as pro_id, product_code, product_name, pro_img, pro_resize_img, pro_thumb_img, tblprospecification.proid as product_id , in_the_box ,model_number, model_name, tblprospecification.color as mobile_color, browse_type, sim_type ,tblcomspecification.proid  as product_id, tblcomspecification.modelname as com_moledname, series, tblcomspecification.color as com_color,  tblledtvpecification.proid, tblledtvpecification.modelname as ledtv_modelname, dsize,stype_id, hd_techno')
->from('tblproducts')
->join('tblprospecification','tblproducts.proid = tblprospecification.proid ' ,'left')
->join('tblcomspecification','tblproducts.proid = tblcomspecification.proid', 'left')
->join('tblledtvpecification','tblproducts.proid = tblledtvpecification.proid' ,'left')
->where('tblproducts.proid',$proid)
->get();
return $query->result();

执行查询时,它将仅从tblproducts和tblprospecification联接后返回数据。它会返回空白数据以进行tblledtvpecification,tblcomspecification。

0 个答案:

没有答案
相关问题