Welcome Guest, Not a member yet? Register   Sign In
Error Number 1054 on CRUD application
#1

[eluser]ede196620[/eluser]
i am getting this error anyone know what is could be the cause of this ? i think its something with the model but cant figure out.

Code:
Error Number: 1054

Unknown column 'id' in 'order clause'

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

Filename: C:\wamp\www\Surva\system\database\DB_driver.php

Line Number: 330

MODEL

Code:
class Display_model extends CI_Model{
    
    
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);

        

}
}


  
?>
#2

[eluser]TheFuzzy0ne[/eluser]
Whats your table structure for tblquestions?
#3

[eluser]TheFuzzy0ne[/eluser]
You have defined your primary key as being "QID", so where's "id" coming from?
#4

[eluser]ede196620[/eluser]
so instead id it should be $primary_key or jest QID ?
#5

[eluser]TheFuzzy0ne[/eluser]
Surely that would be better off written as:

Code:
function get_paged_list($limit=10, $offset=0, $order_column='', $order_type='asc')
{
    // If we don't have a sort column, sort by primary key.
    if ( ! $order_column)
    {
        $order_column = $this->primary_key;
    }

    $this->db->order_by($order_column, $order_type);
    
    return $this->db->get($this->table_name, $limit, $offset);
}
#6

[eluser]ede196620[/eluser]
i tried your example and it dose look like the logical solution but i am still getting the same error
#7

[eluser]TheFuzzy0ne[/eluser]
That's because you're trying to sort by a column that doesn't exist in your database. You have no 'id' column, but you're passing that into the method as the sort column.
#8

[eluser]ede196620[/eluser]
i tried your solution it dose look as the logical solution but i am still getting the same error
#9

[eluser]ede196620[/eluser]
i though i was passing this private $primary_key='QID'; as my id . Is that not correct ?
#10

[eluser]TheFuzzy0ne[/eluser]
Please post your controller code.




Theme © iAndrew 2016 - Forum software by © MyBB