codeigniter 4 order by code example
Example 1: codeigniter order by
$this->db->from($this->table_name);
$this->db->order_by("name", "asc");
$query = $this->db->get();
return $query->result();
Example 2: codeigniter where_not_in
$names = array('Frank', 'Todd', 'James');
$this->db->where_not_in('username', $names);
Example 3: where_in codeigniter
$this->db->select('ae_users.employee_id, ae_users.emp_name, ae_users.emp_name2, ae_users.emp_name3');
$this->db->from('ae_users');
$this->db->where_in('ae_users.employee_id',$employee_ids);
$query =$this->db->get();
if ($query->num_rows()) {
return $query->result_array();
} else {
return 0;
}
Example 4: codeigniter select for update
$table = "my_table";
$id = 1;
$update = ["status"=>"working"];
$query = $this->db->select()
->from($table)
->where('id', $id)
->get_compiled_select();
$data = $this->db->query("$query FOR UPDATE")->row_array();
$this->db->where('id', $data['id'])->update($table,$update);