当我执行此查询时,codeigniter将使用category.id
替换ID字段的值id | category_id | manufacturer_id | title
1 | 4 | 12 | symfony
2 | 4 | 16 | pioneer
3 | 4 | 93 | razer
4 | 4 | 2 | python
$item_id = 3;
$this->db->select("*")
->from("items")
->join("category", "category.id=items.category_id")
->where("items.id", $item_id);
var_dump($this->db->get->result_object());
它返回的是
stdClass::__set_state(array(
'id' => '4',
'category_id' => '4',
'manufacturer_id' => '1',
'title' => 'Floral Swing Dress',
'image_file_name' => 'c62e854fe16c8cc60e508a423f9a14da.jpg',
'price' => '84',
'type' => 'evening_dress',
'parent_id' => '2',
)),
id的值正在被category_id的值替换。 id应为3,但现在为4.
当我在phpmyadmin中执行查询时,我得到了正确的结果。
答案 0 :(得分:0)
您可以尝试这样的事情:
$this->db->select("items.*, category.id as cat_id, category.otherfieldname")
->from("items")
->join("category", "category.id=items.category_id")
->where("items.id", $item_id);