Welcome Guest, Not a member yet? Register   Sign In
Active Record order_by not working with ABS()
#1

[eluser]tkaw220[/eluser]
Below is my code:

$this->db->order_by('format, ABS(title)','asc');
$q = $this->db->get('products');

I even tried these combination:
$this->db->order_by('format','asc');
$this->db->order_by('ABS(title)','asc'); // fail

$this->db->order_by('format asc, ABS(title) asc'); // fail also

It sorted my products by format properly but not the titles. Something wrong with my code? I used ABS() to proper sort product with number 1, 2, ... 10, 11. Without it, the products will be sorted by 10, 1, 2, 3 ...

Thanks.
#2

[eluser]tkaw220[/eluser]
Ok, now I figured out what has went wrong. The correct code should be $this->db->order_by(ABS(title),‘asc’), which give me a result of '0' for title. I think I should not use the ABS() operator in this case. But I do need to sort my products with issue number, ie., Issue 1, 2, 3, ..., 10, ... If I sort it by using order_by('title', 'asc'), it give me 10, 11, 12, 1, 2, 3, ... Where ten always come before one. How do I properly sort it?
#3

[eluser]InsiteFX[/eluser]
Code:
$this->db->order_by('title', 'desc');

InsiteFX
#4

[eluser]tkaw220[/eluser]
Hello InsiteFX,

Not. Order the title in desc manner does not give me the desired result. Anyone, I had already padded all number below 10 with 0, ie., 01, 02, 03, ... This way, it gives me the expected result. Thank you very much for your help. You have been very helpful in this forum.
#5

[eluser]InsiteFX[/eluser]
Your very Welcome!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB