Welcome Guest, Not a member yet? Register   Sign In
Order_by Descending
#1

[eluser]cboyd[/eluser]
I am having trouble with the order_by argument for the Active Records.

I am using:

$this->module_m->order_by('fieldname', 'desc');

as per the documentation, but it is resulting in:

SELECT `id`, `fieldname` FROM `default_tablename` ORDER BY "fieldname", "desc" ASC

rather than:

SELECT `id`, `fieldname` FROM `default_tablename` ORDER BY "fieldname desc"

Any words of wisdom?

Thanks!
#2

[eluser]CroNiX[/eluser]
Strange... show the whole query.
#3

[eluser]cboyd[/eluser]
OK, the problem seems to be that I am passing the information as a variable.

$sort = "'fieldname', 'desc'";

$this->module_m->order_by($sort );

Do I need to do something to the varibale before I pass it?

Thanks
#4

[eluser]CroNiX[/eluser]
If you are passing a single string, according to the docs it looks like it would be written like you were using raw sql like:
Code:
$sort = 'fieldname DESC';
$this->db->order_by($sort);
or
Code:
$fieldname = 'name_of_field';
$order = 'desc';
$this->db->order_by($fieldname, $order);

#5

[eluser]cboyd[/eluser]
That's how I started but it results in this error - "Fatal error: Call to a member function result_object() on a non-object in..."
#6

[eluser]CroNiX[/eluser]
I've never had that problem, which is why I asked to see your whole function instead of just the order_by line. Something else must be going on.
#7

[eluser]cboyd[/eluser]
Thanks, CroNiX. Breaking up the variables into $fieldname and $order variables did the trick. thanks!




Theme © iAndrew 2016 - Forum software by © MyBB