Recently I started building a filter that sorts my data in sphinx, but the thing is – I ran into an interesting CI bug (?). It doesn’t matter in what order I pass my WHERE attributes because CI will simply sort the results on its own.
Why do both of these queries return the same old result and is there a way how this could be fixed?
$a = $this->db->from('table')
->where('id', 1)
->or_where('id', 2)
->get()->result();
$b = $this->db->from('table')
->where('id', 2)
->or_where('id', 1)
->get()->result();
if ($a == $b) echo 'Equal';
The sql queries that are generated produce the identical result sets, that’s why the object sets are identical. This has nothing to do with CI. Most sql dbs will optimize the where parameters to execute most efficiently, not by the order you specify them in (barring parenthasis or order of operation rules).
If you want to change the ordering of your result set from your sql db, you need to use an order by.