• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Active Record] Order by field

#1
Hi there

I'm using CI 3.1.4 and have a problem with 'order by field'.

Code:
...
$this->db->where_in('table.column',$artIDs);
$order = sprintf('FIELD(table.column, %s)', implode(', ', $artIDs));
$this->db->protect_identifiers(FALSE)->order_by($order);
$this->db->limit((int)$limit,(int)$start);

 return $this->db->get();

I'm propably doing something wrong. Can anyone help me? Thanks in advance.
Reply

#2
I suggest u to output your query as a string and try that query in mysql workbench, that way is easier to see errors
PHP Code:
$this->db->where_in('table.column',$artIDs);
$order sprintf('FIELD(table.column, %s)'implode(', '$artIDs));
$this->db->protect_identifiers(FALSE)->order_by($order);
$this->db->limit((int)$limit,(int)$start);


$sql $this->db->get_compiled_select();
echo 
$sql;
return 
$this->db->query($sql); 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.