簡體   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