有没有办法按特定值对 codeigniter 选择查询进行排序?
我知道这可以在 this 的 mysql 中完成回答,但我想知道是否有一种“codeigniter”方法可以做到这一点,这是我尝试过的方法:
$this->db->select('...');
$this->db->from('table_one');
$this->db->join('table_two', 'table_one.some_id = table_two.id', 'inner');
$this->db->where('city',$city);
// this gives me error
$this->db->order_by("table_two.id=$id", "desc");
$query = $this->db->get();
return $query->result_array();
这给了我未知的列错误。
最佳答案
是的,这是可能的,但你需要引号:
$this->db->order_by("table_two.id='$id'", "desc");
提示:您始终可以像这样仔细检查您的查询:
echo $this->db->last_query();die;
关于php - 如何在 Codeigniter 中将行置于顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58368455/