我有一个查询,如何将结果作为数组?
function get_all_transaksi_proses() {
$rs = $this->db->query("SELECT a.id_transaksi,
a.nama,
a.tgl_transaksi,
(SELECT COUNT( id_transaksi ) AS jum
FROM tbl_detail_trs_menu
WHERE id_transaksi = a.id_transaksi) AS jumlah,
a.status_transaksi,
a.total,
b.status_pelanggan,
c.nama_karyawan
FROM tbl_transaksi a
LEFT JOIN tbl_pelanggan b
ON a.id_pelanggan = b.id_pelanggan
LEFT JOIN tbl_karyawan c
ON a.id_karyawan = c.id_karyawan
WHERE a.status_transaksi = 'PROSES' ");
echo json_encode(array("result" => $rs));
}
答案 0 :(得分:5)
像这样:
$rs = $this->db->query(...);
$array = $rs->result_array();
https://www.codeigniter.com/user_guide/database/results.html
答案 1 :(得分:2)
要在数组中获得结果,您必须执行此CI 2.2.2:
return $query->result_array();
答案 2 :(得分:1)
$query = $this->db->query("select....");
return $query->result(); // it will result an array
or
echo json_encode($query->result()); // this will also result array but direct to json_encode
....希望我帮助你!