1

我有两张桌子 competition_registrationcompetition_schedule. 我有 wa select 查询,用于从中选择行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_idcompetition_level_id等于 3 和period_id等于 6 的competition_scheduletable 列。

4

1 回答 1

1

希望对你有帮助 :

competition_schedule.period_id = 6和 thiscompetition_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

于 2018-07-18T07:14:52.157 回答