我想计算game_slopes
中game_created_slopes
的{{1}}条目数,其中id_sector
具有特定值。
基本上我想知道为扇区1创建了多少斜率。
game_slopes
是通用项目表,game_created_slopes
是成员创建的实际项目表。
我尝试进行选择查询,但不确定如何计算。
$this->db->select('game_slopes.id_slope, game_slopes.id_sector, game_created_slopes.id_slope, game_created_slopes.id_player');
$this->db->from('game_slopes, game_created_slopes');
$this->db->join('game_created_slopes as created_slopes_tbl', 'game_slopes.id_slope = created_slopes_tbl.id_slope');
$query = $this->db->get();
CREATE TABLE `game_slopes` (
`id_slope` int(11) NOT NULL,
`id_sector` int(11) NOT NULL,
....more stuff here....
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `game_created_slopes` (
`id_created_slopes` int(11) NOT NULL,
`id_player` int(11) NOT NULL,
`id_slope` int(11) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
如果有更好的方法,我就可以了!
答案 0 :(得分:1)
您可以通过三种方式存档
Count
Function)num_rows()
Function)count
Function)以SQL方式
$this->db->select('COUNT(game_slopes.id_slope) as totalGames , game_slopes.id_slope, game_slopes.id_sector, game_created_slopes.id_slope, game_created_slopes.id_player');
以Codeigniter方式
在$query = $this->db->get();
添加此$totalGames = $query->num_rows();
$query = $this->db->get();
$totalGames = $query->num_rows();
以PHP方式
$query = $this->db->get();
$result = $query->result_array();
$count = count($result);
if (empty($count)) {
return false;
} else {
return $result;
}