List items is not getting sorted

edited December 2012 in Modules
Hi,

I have function list_items(), I am trying to get the list items of my account and also i am joining to user table where i am trying to get its fields, I am getting the list items but not able to sort. I did use this $this->db->debug_query(); query is returning properly but it is not getting sorted, Please help me out

function __construct()
{
parent::__construct('account'); // table name
}

function list_items($limit = NULL, $offset = NULL, $col = 'account.id', $order = 'asc')
{
$CI =& get_instance();
$userdata = $CI->fuel_auth->user_data();
$this->db->join('user', 'user.id = account.account_id', 'left');
$this->db->select('account.id, account.name as Table, user.name as "NAME", account.monthly, account.yearly as "Yearly", account.date');
$this->db->where("account.userid =".$userdata['id']);
$this->db->order_by('account.id', 'desc');
$data = parent::list_items($limit, $offset, $col, '');
return $data;
}

Comments

  • edited 1:16PM
    Have you tried removing the order_by part that you added? You will also need to change the second to last line to the following:
    parent::list_items($limit, $offset, $col, $order);

    If you are needing to sort it by default you can use the "default_col" and "default_order" in you module's config.
  • edited 1:16PM
    I tried parent::list_items($limit, $offset, $col, $order); and also removed order_by but we get SQL error while loading a list_items() says "name is ambiguous in order_by clause "
  • edited 1:16PM
    it's because you are using a join that has a name field in it. Try prefixing the column name with the table name before adding it to the order_by statement
  • edited March 2013
    I've run in to a similar issue with a list item not sorting but I think it has to do with the field name alias. I'm using 1.0 by the way. I have a select statement that uses tablename.fieldname as 'Display Name' in a few places and anywhere the alias is used the sort doesn't work. When I remove the alis and use the default field name, sorting is restored. Just discovered this today.

    Anyone know if this is a bug or if there's something I'm missing that might enable use of aliases?
Sign In or Register to comment.