繁体   English   中英

Codeigniter join返回最后一个id

[英]Codeigniter join gives last id back

我希望从我的表'device_id'获取id,但我一直从'inventory'获取id,因为它是最后一个连接。

我试图在互联网上查找,但可以找到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。

表名赋给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']);

简单而棘手的一个。 所有你需要做一些改变..

$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']);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM