php - how to return an array with like keyword on codeigniter's active record -
i want perform query wth active records :
select * tablename status = 'a' , name 'test'
and want return array because want encode json
later, need use result_array();
so tried :
$query = $this->db->select('*')->from('tablename')->where('status', 'a'); $query->like('name', 'test')->get()->result_array(); return $query;
but got message when tried encode json
:
type unsupported, encoded null
what should do? help.
try this:
$data = array(); $rs = $this->db->where('status', 'a')->like('name', 'test')->get('tablename'); if($rs->num_rows()> 0){ $data = $rs->result_array(); } return $data;
Comments
Post a Comment