1

is there a way to order codeigniter select query by a specific value?

I know that it can be done in mysql from this answer, but I'm wondering if there is a "codeigniter" way of doing it, here is what I've tried:

$this->db->select('...');
$this->db->from('table_one');
$this->db->join('table_two', 'table_one.some_id = table_two.id', 'inner');
$this->db->where('city',$city);
// this gives me error
$this->db->order_by("table_two.id=$id", "desc");   
$query = $this->db->get();

return $query->result_array();

This gives me the unknown column error.

failedCoder
  • 1,346
  • 1
  • 14
  • 38

1 Answers1

1

yes this is possible, but you need quotes:

$this->db->order_by("table_two.id='$id'", "desc");   

hint: you can always doublecheck your query like this:

echo $this->db->last_query();die;
Vickel
  • 7,879
  • 6
  • 35
  • 56