Php 如何在codeigniter';s的活动记录
我想使用活动记录执行此查询:Php 如何在codeigniter';s的活动记录,php,sql,json,codeigniter,Php,Sql,Json,Codeigniter,我想使用活动记录执行此查询: SELECT * FROM tablename WHERE status = 'A' AND name LIKE 'test' 我希望它返回一个数组,因为我想稍后将其编码为json,所以我需要使用result\u array() 所以我试过这样的方法: $query = $this->db->select('*')->from('tablename')->where('status', 'A'); $query->like('name
SELECT * FROM tablename WHERE status = 'A' AND name LIKE 'test'
我希望它返回一个数组,因为我想稍后将其编码为json
,所以我需要使用result\u array()代码>
所以我试过这样的方法:
$query = $this->db->select('*')->from('tablename')->where('status', 'A');
$query->like('name', 'test')->get()->result_array();
return $query;
但当我尝试将其编码为json时,我收到了这个消息:
type is unsupported, encoded as null
我该怎么办?谢谢你的帮助。试试这个:
$data = array();
$rs = $this->db->where('status', 'A')->like('name', 'test')->get('tablename');
if($rs->num_rows()> 0){
$data = $rs->result_array();
}
return $data;
此代码结构不会给出任何错误:-
$this->db->where('status', 'A');
$this->db->like('name', 'test')
$query=$this->db->get(tablename);
$data=$query->result();
$json_data=json_encode($data);
请看一看示例。@HashemQolami它并没有真正的帮助,但我不愿意看到详细信息:DLOL,该页面中没有ID
,否则我会发布一个指向特定部分的链接;)非常感谢,我稍后会接受你的回答,因为系统不允许我现在就这么做。我应该仔细看看哪里必须使用才能得到。很高兴帮助:D@BlazeTamaThanks谢谢你的帮助。我更喜欢用主动语态records@BlazeTama请现在查收。