db->where($where); $this->db->fr-6ren">
gpt4 book ai didi

php - 如何在codeigniter数据库中查询

转载 作者:行者123 更新时间:2023-11-29 12:21:41 24 4
gpt4 key购买 nike

    $this->db->select('*');
$where = "(rank = '2')";
$this->db->where($where);
$this->db->from('deceased');
$this->db->join('causes', 'causes.id = deceased.id');

我有一个来自 codeigniter 的查询,我应该得到排名 2,但问题是,如果没有排名 2,我应该得到排名 1。

db_deceased(id主键)

id date_died
1 2014-01-01
2 2014-03-19

db_causes(id 外键)

id  cause   rank
1 J96.0 1
1 J44.1 2
2 I21 1

最佳答案

也许你应该尝试使用 $this->db->or_where(); 或者 $this->db->or_where_in(); 但也要考虑文档的方法在那里写论点。您的 $where 变量应该类似于 $where = array('name =' => '2');

$this->db->select('*');
$this->db->where('name =', '2');
$this->db->or_where('name =', '1');
$this->db->from('deceased');
$this->db->join('causes', 'causes.id = deceased.id');

documentation 中对事件记录进行了很好的解释。 .

关于php - 如何在codeigniter数据库中查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28926773/

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