0

codeigniter当我以活动记录形式执行查询时,我得到了不同的结果MyPhpAdmin

以下查询使用MyPhpAdmin

SELECT * FROM (`ingredients`) LEFT JOIN `product_ingredients` ON `ingredients`.`ingredient_id` = `product_ingredients`.`ingredient_id` AND `product_id` = 46

给出所需的结果,其中包括返回的两个成分记录的成分 ID。

Array ( [0] => stdClass Object ( [ingredient_id] => 1 [display] => Sweet Almond Oil [slug] => sweet-almond-oil [title] => Sweet Almond Oil [description] => Sweet Almond Oil [featured_image_url] => [product_ingredient_id] => 10 [product_id] => 46 [display_position] => 2 [key_ingredient] => 0 ) [1] => stdClass Object ( [ingredient_id] => 2 [display] => Shea Butter [slug] => shea-butter [title] => Shea Butter [description] => Shea Butter [featured_image_url] => [product_ingredient_id] => [product_id] => [display_position] => [key_ingredient] => ) )

Codeigniter但是,如果我使用带有以下代码的活动记录执行此查询:

$this->db->select('*');
$this->db->join('product_ingredients', 'ingredients.ingredient_id = product_ingredients.ingredient_id AND `product_id` = 46', 'left');
$query = $this->db->get('ingredients'); 

然后生成的数组缺少第二个成分结果的成分 ID,即:

Array ( [0] => stdClass Object ( [ingredient_id] => 1 [display] => Sweet Almond Oil [slug] => sweet-almond-oil [title] => Sweet Almond Oil [description] => Sweet Almond Oil [featured_image_url] => [product_ingredient_id] => 10 [product_id] => 46 [display_position] => 2 [key_ingredient] => 0 ) [1] => stdClass Object ( [ingredient_id] => [display] => Shea Butter [slug] => shea-butter [title] => Shea Butter [description] => Shea Butter [featured_image_url] => [product_ingredient_id] => [product_id] => [display_position] => [key_ingredient] => ) )

任何帮助将非常感激...

4

1 回答 1

0

一探究竟

$this->db->select('i.*');
$this->db->from('ingredients i');
$this->db->join('product_ingredients pi', 'i.ingredient_id = pi.ingredient_id', 'left');
$this->db->where('pi.product_id',46);
$query = $this->db->get()->result_array(); 
于 2013-06-27T06:34:12.643 回答