gpt4 book ai didi

php - 将 MySQL JOIN 查询转换为 CodeIgniter 查询

转载 作者:行者123 更新时间:2023-11-29 06:46:03 27 4
gpt4 key购买 nike

我正在尝试将此查询转换为代码点火器查询。但我不知道从哪里开始。我是代码点火器的新手。请帮忙。

public function  get_loginsecuritydetails($security_date,$apt_id) {

$sql = "SELECT s.* , IF( DATE( s.security_date ) = DATE( '$security_date' ) , 1, 0 ) AS loginstatus,a.agency_companyname FROM security s JOIN agency a ON(a.agency_id=s.security_cat) WHERE apartment_id='$apt_id'; ";
$res=mysqli_query($sql) or die(mysqli_error());
return $res;
}

最佳答案

您可以在 codeigniter 查询生成器中将其转换,如下所示:

$this->db->select("s.* , IF( DATE( s.security_date ) = DATE( '$security_date' ) , 1, 0 ) AS loginstatus,a.agency_companyname");

$this->db->join("agency as a","a.agency_id=s.security_cat");

$this->db->where('apartment_id',$apt_id);

$query = $this->db->get('security as s');

$result = $query->result();

return $result;

关于php - 将 MySQL JOIN 查询转换为 CodeIgniter 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49382456/

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