代码点火器向自定义查询添加“订购依据”

时间:2018-12-21 11:10:30

标签: postgresql codeigniter-3

在一个简单的自定义查询上,CodeIgniter添加一个“ Order by”子句。查询是

  $sql = "SELECT city_location  
            FROM admin_users  
            WHERE id = " . $_SESSION['admin']['user_id'] . " 
            ORDER BY id asc 
            LIMIT 1";

    $query = $this->db->query($sql);

结果是在我运行$ query = $ this-> db-> query($ sql)之后:

ERROR: column "name" does not exist LINE 4: ORDER BY "name" ASC ^

SELECT "city_location" 
        FROM "admin_users" 
        WHERE "id" = '61' 
        ORDER BY "name" 
        ASC LIMIT 1

问题是:为什么codeigniter将默认的ORDER BY添加到我的查询中。该模型不包含任何默认顺序。

谢谢

1 个答案:

答案 0 :(得分:0)

您将尝试使用cod $ this-> db-> select('city_location'); //列名

$this->db->from('admin_users');// Table name
$this->db->where('id' , $_SESSION['admin']['user_id']);// Your condition Here.First parameter is columnname and second one is value
$this->db->order_by('id');