[英]how to fetch record in codeigniter where clause using json values
My question is in my table stored json encoded values like field Name : offer_promotion
我的问题是在我的表中存储了json编码的值,如
field Name : offer_promotion
[{"name":"sample promotion","price":"1555","expdate":"2017-05-15","shortdesc":"test","longdesc":"test"}]
Now i want to write query for select records like, For eaxmple: 现在我想为选择记录编写查询,例如,对于eaxmple:
$this->db->where('offer_promotion', "name":"sample promotion");
How to write this query? 怎么写这个查询?
json in database works as a simple string. 数据库中的json作为一个简单的字符串。 So you have to apply logic similar as string.
所以你必须应用类似于字符串的逻辑。 You can use Like
你可以使用Like
$this->db->like('offer_promotion', '%"name":"sample promotion"%');
$some = json_decode($json);
$this->db->where('offer_promotion',$some['name']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.