【发布时间】:2019-07-18 09:05:52
【问题描述】:
我想用 Codeigniter 从我的数据库中返回一些数据。该查询是来自所有相关表的连接。 这是图表:
来自模型的连接查询:
public function combine_all_data_related($hostname){
$this->db->select('*');
$this->db->from('workstations w');
$this->db->join('occupations o', 'w.occupation_id = o.occupation_id', 'left');
$this->db->join('departments d', 'd.department_id = o.department_id', 'left');
$this->db->join('workstation_configuration wc', 'wc.service_tag = w.service_tag', 'left');
$this->db->join('workstation_models wm', 'wm.workstation_model_id = wc.workstation_model_id', 'left');
$this->db->join('workstation_types wt', 'wt.workstation_type_id = wm.workstation_type_id', 'left');
$this->db->join('users u', 'u.occupation_id = o.occupation_id', 'left');
$this->db->join('phone_numbers pn', 'pn.fmid = u.fmid', 'left');
$this->db->join('phones p', 'p.phone_number_id = pn.phone_number_id', 'left');
$this->db->join('phone_brands pb', 'pb.phone_brand_id = p.phone_brand_id', 'left');
$this->db->where("w.hostname = '" . $hostname . "'");
$query = $this->db->get();
return $return = $query->result();
}
这里是浏览器中的 var_dumps 结果 SQL 语句和返回的数据。获取日期、最新编辑和状态不OK的记录。
【问题讨论】:
-
试试这个 echo $this->db->last_query();在 $query 语句之后
-
最后一张图片的第一段是 print_r($this->db->last_query());
-
能否请您给出sql转储,以便我们识别
-
工作站和电话表中有 aquisition_date 字段,因为电话表在查询的后面加入,它的值覆盖第一个,为这些字段提供不同的别名。
-
请显示最后的 sql 转储。由于 LEFT JOIN,它可能为 null。
标签: php mysql codeigniter