gpt4 book ai didi

php - CI 模型中的 where_not_in 代码

转载 作者:行者123 更新时间:2023-11-29 13:55:57 25 4
gpt4 key购买 nike

编码员您好,我正在尝试在 CODE IGNITER 模型中编写此 mysql 脚本,但没有获得正确的脚本,如何将其编码到事件记录中,您可以帮助我吗

SELECT bus_reg_number
FROM t_bus_detail
WHERE bus_reg_number NOT
IN (

SELECT bus_reg_number
FROM t_bus_alot
)

我的模型

 public function get_bus_reg_number()
{


$this->db->select('bus_reg_number')->from('t_bus_detail');
$result=$this->db->where_not_in('bus_reg_number' NOT IN (SELECT 'bus_reg_number' FROM 't_bus_alot')');



$dropdown_bus_number = array();
foreach($result as $r)
{
$dropdown_bus_number[$r['bus_reg_number']] = $r['bus_reg_number'];

}
return $dropdown_bus_number;
}

最佳答案

$this->db->select('bus_reg_number');
$this->db->from('t_bus_detail');
$this->db->where('`bus_reg_number` NOT IN (SELECT `bus_reg_number` FROM `t_bus_alot`)', NULL, FALSE);

试试这个.. null 和 false 会告诉 CI 不要转义你的 where 查询..

编辑:这是简单的查询:

$query = $this->db->query("SELECT bus_reg_number FROM t_bus_detail WHERE bus_reg_number NOT IN (SELECT bus_reg_number FROM t_bus_alot)");
$dropdown_bus_number = array();
foreach ($query->result_array() as $row){
$dropdown_bus_number[$row['bus_reg_number']] = $row['bus_reg_number'];
}

关于php - CI 模型中的 where_not_in 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15864501/

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