Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CodeIgniter-secound表中没有行时MySQL连接_Mysql_Codeigniter - Fatal编程技术网

CodeIgniter-secound表中没有行时MySQL连接

CodeIgniter-secound表中没有行时MySQL连接,mysql,codeigniter,Mysql,Codeigniter,我在模型中有此查询: 我的目标是列出游戏中的所有内容,另外在可用时从费率中获得平均费率。现在它只显示两个表中的行。如何解决此问题?使用此说明 $this->db->select('games.id, games.title, games.slug, games.dev_id, games.dev, games.plat_id, games.plat'); $this->db->select_avg('rates.rate'); $this->db->from(

我在模型中有此查询:

我的目标是列出
游戏
中的所有内容,另外在可用时从
费率
中获得平均
费率
。现在它只显示两个表中的行。如何解决此问题?

使用此说明

$this->db->select('games.id, games.title, games.slug, games.dev_id, games.dev, games.plat_id, games.plat');
$this->db->select_avg('rates.rate');
$this->db->from('games');
$this->db->join('rates', 'games.id = rates.game_id','left');
$this->db->group_by('rates.game_id');
$q = $this->db->get();

左连接将带来多个结果。使用avg和group by将限制对每条记录只提取一行。

我尝试使用
左外
等,但没有任何结果;(另外,
导致
id
游戏
切换到
费率
,这是我不想做的。对于平均费率,请使用$this->db->select_avg('rates.rate'))并将game.id的别名指定为GameId以防止冲突,以及为什么您要以$q分配每个指令。最后要使用的是按速率分组。game_id和所有内容都将是doneYes,分组帮助(由于某些原因,这一点根本不需要)。谢谢!(另外,请编辑您的答案,以便我可以对其进行投票;)
    return $q->result();
}
$this->db->select('games.id, games.title, games.slug, games.dev_id, games.dev, games.plat_id, games.plat');
$this->db->select_avg('rates.rate');
$this->db->from('games');
$this->db->join('rates', 'games.id = rates.game_id','left');
$this->db->group_by('rates.game_id');
$q = $this->db->get();