首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Codeigniter活动记录响应与MyPhpAdmin SQL查询不同

Codeigniter活动记录响应与MyPhpAdmin SQL查询不同
EN

Stack Overflow用户
提问于 2013-06-26 19:32:42
回答 1查看 126关注 0票数 0

codeigniter活动记录表单MyPhpAdmin中执行查询时得到不同的结果

以下查询使用MyPhpAdmin运行

代码语言:javascript
复制
SELECT * FROM (`ingredients`) LEFT JOIN `product_ingredients` ON `ingredients`.`ingredient_id` = `product_ingredients`.`ingredient_id` AND `product_id` = 46

给出所需的结果,其中包括返回的两个配料记录的ingredient_id。

代码语言:javascript
复制
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活动记录执行此查询:

代码语言:javascript
复制
$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'); 

则结果数组缺少第二个配料结果的ingredient_id,即:

代码语言:javascript
复制
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] => ) )

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2013-06-27 14:34:13

看看这个

代码语言:javascript
复制
$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(); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17318862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档