Welcome Guest, Not a member yet? Register   Sign In
two order by clause in sql query
#1

[eluser]core-coder[/eluser]
Hi, I want to execute a query with two order by clause as

Code:
SELECT * FROM `categories` ORDER BY `categories_order` ASC, `categories_name` ASC

How can I achieve using codeignter database class ?

Thank you guys
#2

[eluser]puzzlebox[/eluser]
is $this->db->query($query) not ok? hmmmm
#3

[eluser]Armchair Samurai[/eluser]
Assuming you mean CI Active Record, just call order_by() two times, once for each clause, just pass your own string to order_by().

Code:
$this->db->order_by('categories_order', 'asc');
$this->db->order_by('categories_name', 'asc');

$query = $this->db->get('categories');

// OR

$this->db->order_by('categories_order ASC, categories_name ASC');

$query = $this->db->get('categories');
#4

[eluser]core-coder[/eluser]
thanks but I am trying to get it by something like $this->db->order_by("categories_order", "ASC"); ...

ant hope ?
#5

[eluser]core-coder[/eluser]
[quote author="Armchair Samurai" date="1267189924"]Assuming you mean CI Active Record, just call order_by() two times, once for each clause, just pass your own string to order_by().

Code:
$this->db->order_by('categories_order', 'asc');
$this->db->order_by('categories_name', 'asc');

$query = $this->db->get('categories');

// OR

$this->db->order_by('categories_order ASC, categories_name ASC');

$query = $this->db->get('categories');
[/quote]

Thanks I got it by $this->db->order_by('categories_order ASC, categories_name ASC');




Theme © iAndrew 2016 - Forum software by © MyBB