如何在代码点火器中使用连接查询从表中选择行?



我有两个表competition_registrationcompetition_schedule。我有 wa 选择查询用于从competition_registration中选择行。这是我的代码,如下所示:

$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;

但这显示了错误。任何人都可以检查此查询并为我纠正它吗?

我想从两个表中选择具有相同competition_schedule_id的列,并且competition_level_id等于 3 且period_id等于 6competition_schedule表中。

希望这会对您有所帮助:

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

相关内容

  • 没有找到相关文章

最新更新