gpt4 book ai didi

mysql - 将 mysql 查询转换为 CodeIgniter $query->row

转载 作者:行者123 更新时间:2023-11-29 09:42:20 25 4
gpt4 key购买 nike

如何将此查询转换为 CodeIgniter?

$date = '28-05-2019';
$time_start = '10:00';
$time_end = '19:00';

select courtrooms.* from courtrooms
left join reservations
on courtrooms.id = reservations.courtroom_id
and reservations.date = '$date' and reservations.time_start < '$time_start' and reservations.time_end > '$time_end'
where reservations.id is null

最佳答案

实际上有多种方法可以在 Codeigniter 中编写查询,如果您刚刚开始使用此框架编写查询,那么从我的角度来看,以下语法是最容易理解的。

请参阅Query Builder Class

$this->db->select('*');
$this->db->from('courtrooms');
$this->db->join('reservations','courtrooms.id = reservations.courtroom_id','left');
$this->db->where('reservations.id IS NULL', null, false);
$this->db->where('reservations.date', $date);
$this->db->where('reservations.time_start<', $time_start);
$this->db->where('reservations.time_end>', $time_end);
$query = $this->db->get();

$query = $query->result();

上面的代码与下面的代码相同:

$query = $this->db->join('reservations','courtrooms.id = reservations.courtroom_id','left')
->where('reservations.id IS NULL', null, false)
->where('reservations.date', $date)
->where('reservations.time_start<', $time_start)
->where('reservations.time_end>', $time_end)
->get('courtrooms');
$query = $query->result();

关于mysql - 将 mysql 查询转换为 CodeIgniter $query->row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56349037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com