我想从表“ device_id”中获取ID,但是我一直从“库存”获取ID,因为这是最后一次联接。
我试图在Internet上查找它,但可以找到Codeigniter的解决方案。
$this->db->where('device_id', $this->input->get('device_id'));
$this->db->join('repair_components', 'repair_options.component_id = repair_components.id');
$this->db->join('products', 'repair_options.product_id = products.id');
$this->db->join('inventory', 'repair_options.product_id = inventory.product_id', 'left');
$query = $this->db->get('repair_options');
$this->data['options'] = $query->result();
print_r($this->data['options']);
我想要数组'$ this-> data ['options']'中'device_id'的ID。
答案 0 :(得分:0)
给表名到 where 子句中的列,并确保$this->input->get('device_id')
里面有值。
$this->db->join('repair_components', 'repair_options.component_id = repair_components.id');
$this->db->join('products', 'repair_options.product_id = products.id');
$this->db->join('inventory', 'repair_options.product_id = inventory.product_id', 'left');
$this->db->where('table_name.device_id', $this->input->get('device_id'));
$query = $this->db->get('repair_options');
$this->data['options'] = $query->result();
print_r($this->data['options']);
答案 1 :(得分:0)
简单但棘手的一个。您需要做的所有更改。.
$this->db->select('*,device_id.id as the_device_id');
$this->db->from('repair_options');
$this->db->where('device_id', $this->input->get('device_id'));
$this->db->join('repair_components', 'repair_options.component_id = repair_components.id');
$this->db->join('products', 'repair_options.product_id = products.id');
$this->db->join('inventory', 'repair_options.product_id = inventory.product_id', 'left');
$query = $this->db->get();
$this->data['options'] = $query->result();
print_r($this->data['options']);