【问题标题】:Error Number 1054 on CRUD applicationCRUD 应用程序上的错误号 1054
【发布时间】:2013-03-15 08:27:22
【问题描述】:

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

错误号: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);
}

【问题讨论】:

    标签: php codeigniter model error-handling


    【解决方案1】:

    请将 id 改为 qid 为:

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

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

    【讨论】:

    • @user2143150 你的意思是 qid 是大写的,即 QID 对! ,好吧,在数据库中没关系,数据库仅在用户价值上有所不同,即我们的数据不是表结构
    • 所以字母是大写还是小写都没关系?
    • 是的,因为它的结构(即表列名等),它对用户输入的值很重要,即用户在表中输入的数据区分大小写
    • 我根本没有得到这个
    【解决方案2】:

    在使用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');  
    

    【讨论】:

    • 我是 codeigniter 的新手,真的不明白你说什么,你能解释一下我将如何做这件事吗? tnx 用于回答 bdv。
    • 用这个SELECT ID FROM (tblquestions) ORDER BY ID asc LIMIT 5替换你的查询我的意思是用列名替换“*”
    • 我要把它放在 $this->db->order_by 行吗?
    • 这里你可以改变这个--- $this->db->order_by($this->primary_key,'asc'); to $this->db->order_by("tblquestions".$this->primary_key,'asc');
    • 这是一个示例 yaar... 我的意思是该错误意味着您正在尝试order by 一个在多个表中使用的列名。使用包含您要排序的列的表的名称更新您的 order_by 语句。
      例如:$this->db->order_by('Employee.id');
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-11
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 2015-10-29
    • 2017-01-10
    相关资源
    最近更新 更多