0

我收到这个错误有人知道这可能是什么原因吗?我认为它与模型有关,但无法弄清楚。

错误号:1054

“订单子句”中的未知列“id”

SELECT * FROM (tblquestions ) ORDER BY id asc LIMIT 5

文件名:C:\wamp\www\Surva\system\database\DB_driver.php

行号:330

模型

private $primary_key = 'QID';
private $table_name = 'tblquestions';

function get_paged_list($limit=10, $offset=0, $order_column='', $order_type='asc')
{
    if (empty($order_column) || empty($order_type)) {
        $this->db->order_by($this->primary_key, 'asc'); 
    }
    else {
        $this->db->order_by($order_column, $order_type);
        return $this->db->get($this->table_name, $limit, $offset);
    }
}

function count_all()
{
    return $this->db->count_all($this->table_name); 
}

function get_by_id($id)
{
    $this->db->where($this->primary_key, $id);
    return $this->db->get($this->table_name);
}

function save($question)
{
    $this->db->insert($this->table_name, $question);
    return $this->db->insert_id();  
}

function update($id,$question)
{
    $this->db->where($this->primary_key, $id);  
    $this->db->update($this->table_name, $question);
}

function delete($id)
{
    $this->db->where($this->primary_key, $id);
    $this->db->delete($this->table_name);
}
4

2 回答 2

1

请将 id 更改为 qid 为:

      SELECT * FROM (tblquestions) ORDER BY qid asc LIMIT 5

您在查询中给出了错误的列名。

于 2013-03-15T09:26:14.733 回答
0

order by, having, group by包括使用子句时要选择的所有列。说——SELECT ID FROM (tblquestions) ORDER BY ID asc LIMIT 5
或者如果你也想这样做SELECT * FROM (tblquestions) ORDER BY tblquestions.ID asc LIMIT 5

必须在应用order by, having, group by子句之前专门选择 ColumnName。

Here you can change this---
$this->db->order_by($this->primary_key,'asc');  to
$this->db->order_by("tblquestions".$this->primary_key,'asc');  
于 2013-03-15T08:34:04.233 回答