gpt4 book ai didi

php - CodeIgniter get_where order_by

转载 作者:可可西里 更新时间:2023-10-31 22:18:14 31 4
gpt4 key购买 nike

我想像这样使用 get_where 和 order_by...

$query = $this->db->get_where($this->tbl_name, $where)->order_by('birth_date', 'ASC');

但是出现了这个错误...

Fatal error: Call to undefined method CI_DB_mysql_result::order_by() in C:\xampp\htdocs\OAWA\application\models\Member_model.php on line 82

我做错了什么?

最佳答案

在 CodeIgniter 的 Active Record 中,除了返回结果集的 getget_where 之外,每个方法都返回对象本身(这允许方法链接)。

因此,您需要做的是:

$query = $this->db->order_by('birth_date', 'ASC')->get_where($this->tbl_name, $where);

get_where() 调用必须是最后一个。它返回结果集,因此在 get_where() 之后调用 order_by() 试图在无效的结果集上调用它。

编辑

还有其他方法可以编写此查询:

 $query = $this->db->from($this->tbl_name)->where($where)->order_by('birth_date', 'ASC')->get();

关于php - CodeIgniter get_where order_by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13325962/

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