0

I've seen the documentation on ellislab.com, but I still don't get it. There is no full example. How I'm supposed to use the order_by method?

No effect using none of these:

$fields = $this->db->list_fields($tableName);
$this->db->order_by($fields[0], "desc");
$tableQ = $this->db->get($tableName);

or these

$tableQ = $this->db->get($tableName)->order_by($fields[0], "desc");
van_folmert
  • 4,257
  • 10
  • 44
  • 89
  • that looks ok to me - can you var_dump($fields) & echo $this->db->last_query() and just check your output for us? – jmadsen Oct 19 '13 at 10:56
  • you mean the first one is ok or the second one? when using first one nothing changes, when using second one I get fatal error `Call to undefined method CI_DB_postgre_result::order_by()`. `$fields` are ok for sure, it is an array. – van_folmert Oct 19 '13 at 11:21
  • The second one is in the wrong order. The first one looks fine, but I would try hard coding the field name you want to order by to test it. – Jeemusu Oct 19 '13 at 11:29
  • yeah, I needed to separately declare the conditions, then run the query, as it was adviced in [this topic](http://stackoverflow.com/questions/5320395/codeigniter-order-by-on-a-query) – van_folmert Oct 19 '13 at 11:31
  • the first one should have worked for you – jmadsen Oct 19 '13 at 14:29
  • certainly have to call `order_by` before `get`, can't set the query parameters after query is made – charlietfl Oct 19 '13 at 16:09

0 Answers0