Reputation: 97
I am trying to order by position on my query but set the zero to last. Here is the pseudo code
$this->db->select("id,position");
$this->db->order_by('-position', 'ASC' );
$result = $this->db->get( 'SampleTable' );
Codeigniter treats the query as
SELECT `id`,`position` FROM `TABLE` ORDER BY `-position` ASC thus having an error
Is there any way I can pass the - minus so that the query would be
SELECT `id`,`position` FROM `TABLE` ORDER BY -`position` ASC
Upvotes: 1
Views: 1484
Reputation: 449
You can try this.
$this->db->select("id,position");
$this->db->order_by('(position * -1)', 'ASC' );
$result = $this->db->get( 'SampleTable' );
Upvotes: 1