-1
 $query = ('SELECT tb_imam.*, tb_bidang.bidang FROM tb_imam JOIN tb_bidang ON tb_imam.bidang_id = tb_bidang.id WHERE tb_imam.status = "Pengerja" '); return $this->db->query($query)->result_array(); 

How do I add an order by using my code like this? beg for your help, thank you

2
  • Since you're using a raw SQL string anyway, just add it to the raw string e.g. $query = ('SELECT tb_imam.*, tb_bidang.bidang FROM tb_imam JOIN tb_bidang ON tb_imam.bidang_id = tb_bidang.id WHERE tb_imam.status = "Pengerja" ORDER BY something '); Commented Jan 20, 2020 at 10:42
  • Solved...!! thank you verry much,, Commented Jan 20, 2020 at 10:48

3 Answers 3

1

Here you are using raw query like mysql query, so you can directly add "order by" clause at the end of the "where" clause,

 $query = ('SELECT tb_imam.*, tb_bidang.bidang FROM tb_imam JOIN tb_bidang ON tb_imam.bidang_id = tb_bidang.id WHERE tb_imam.status = "Pengerja" ORDER BY column_name'); return $this->db->query($query)->result_array(); 
Sign up to request clarification or add additional context in comments.

Comments

1

Just use ORDER BY

$query = "SELECT tb_imam.*, tb_bidang.bidang FROM tb_imam JOIN tb_bidang ON tb_imam.bidang_id = tb_bidang.id WHERE tb_imam.status = 'Pengerja' ORDER BY prefix.column_name"; return $this->db->query($query)->result_array(); 

JOIN !== LEFT JOIN

Get used to Query Builder Class.

Comments

0
$this->db->select("tb_imam.*,tb_bidang.bidang"); $this->db->from("tb_imam"); $this->db->join("tb_bidang","tb_imam.bidang_id = tb_bidang.id"); $this->db->where("tb_imam.status","Pengerja"); $this->db->order_by("column_name"); $this->db->get()->result_array(); 

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.