如何使用 codeigniter 中的连接查询 table 中的 select 行?
How to select rows from a table using join query in codeigniter?
我有两个 table competition_registration
和 competition_schedule
。我已经 select 从 competition_registration
查询 selecting 行。这是我的代码,如下所示:
$this->db->select('competition_registration.permenent_registration_number');
$this->db->from('competition_registration');
$where = "permenent_registration_number is NOT NULL";
$this->db->where($where);
$this->db->join('competition_schedule', 'competition_schedule.competition_schedule_id = competition_registration.competition_schedule_id');
$this->db->join('competition_schedule', 'competition_schedule.period_id = 6');
$this->db->join('competition_schedule', 'competition_schedule.competition_level_id = 3');
$query = $this->db->get(); echo $this->db->last_query();exit;
但这显示错误。任何人都可以检查此查询并为我纠正吗?
我想 select 两个 table 中具有相同 competition_schedule_id
和 competition_level_id
等于 3 和 period_id
等于 6 的列competition_schedule
table .
希望对您有所帮助:
将 competition_schedule.period_id = 6
和这个 competition_schedule.competition_level_id = 3
放在 where 子句中,如下所示:
$this->db->select('competition_registration.permenent_registration_number');
$this->db->from('competition_registration');
$this->db->join('competition_schedule', 'competition_schedule.competition_schedule_id = competition_registration.competition_schedule_id');
$where = "competition_registration.permenent_registration_number is NOT NULL";
$this->db->where($where);
$this->db->where('competition_schedule.period_id' , '6');
$this->db->where('competition_schedule.competition_level_id','3');
//$this->db->join('competition_schedule', 'competition_schedule.period_id = 6');
//$this->db->join('competition_schedule', 'competition_schedule.competition_level_id = 3');
$query = $this->db->get();
echo $this->db->last_query();
exit;
更多:https://www.codeigniter.com/user_guide/database/query_builder.html
我有两个 table competition_registration
和 competition_schedule
。我已经 select 从 competition_registration
查询 selecting 行。这是我的代码,如下所示:
$this->db->select('competition_registration.permenent_registration_number');
$this->db->from('competition_registration');
$where = "permenent_registration_number is NOT NULL";
$this->db->where($where);
$this->db->join('competition_schedule', 'competition_schedule.competition_schedule_id = competition_registration.competition_schedule_id');
$this->db->join('competition_schedule', 'competition_schedule.period_id = 6');
$this->db->join('competition_schedule', 'competition_schedule.competition_level_id = 3');
$query = $this->db->get(); echo $this->db->last_query();exit;
但这显示错误。任何人都可以检查此查询并为我纠正吗?
我想 select 两个 table 中具有相同 competition_schedule_id
和 competition_level_id
等于 3 和 period_id
等于 6 的列competition_schedule
table .
希望对您有所帮助:
将 competition_schedule.period_id = 6
和这个 competition_schedule.competition_level_id = 3
放在 where 子句中,如下所示:
$this->db->select('competition_registration.permenent_registration_number');
$this->db->from('competition_registration');
$this->db->join('competition_schedule', 'competition_schedule.competition_schedule_id = competition_registration.competition_schedule_id');
$where = "competition_registration.permenent_registration_number is NOT NULL";
$this->db->where($where);
$this->db->where('competition_schedule.period_id' , '6');
$this->db->where('competition_schedule.competition_level_id','3');
//$this->db->join('competition_schedule', 'competition_schedule.period_id = 6');
//$this->db->join('competition_schedule', 'competition_schedule.competition_level_id = 3');
$query = $this->db->get();
echo $this->db->last_query();
exit;
更多:https://www.codeigniter.com/user_guide/database/query_builder.html