$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();
如何使用我的代码添加订单? 恳求您的帮助,谢谢
这里你使用的是像 mysql 查询这样的原始查询,所以你可以直接在 "where" 子句的末尾添加 "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 column_name');
return $this->db->query($query)->result_array();
只需使用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
习惯查询生成器类。
$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();