如何使用json值在codeigniter where子句中获取记录

时间:2021-12-11 07:39:49

My question is in my table stored json encoded values like field Name : offer_promotion

我的问题是在我的表中存储了json编码的值,比如字段名: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:

现在我想为select记录编写查询,比如eaxmple:

$this->db->where('offer_promotion', "name":"sample promotion");

How to write this query?

如何编写此查询?

2 个解决方案

#1


3  

json in database works as a simple string. So you have to apply logic similar as string. You can use Like

在数据库中json作为一个简单的字符串。所以你必须运用和字符串相似的逻辑。您可以使用像

$this->db->like('offer_promotion', '%"name":"sample promotion"%');

#2


1  

  1. $some = json_decode($json);
  2. 美元$一些= json_decode(json);
  3. $this->db->where('offer_promotion',$some['name']);
  4. $ this - > db - >,(“offer_promotion”,一些美元['名字']);

#1


3  

json in database works as a simple string. So you have to apply logic similar as string. You can use Like

在数据库中json作为一个简单的字符串。所以你必须运用和字符串相似的逻辑。您可以使用像

$this->db->like('offer_promotion', '%"name":"sample promotion"%');

#2


1  

  1. $some = json_decode($json);
  2. 美元$一些= json_decode(json);
  3. $this->db->where('offer_promotion',$some['name']);
  4. $ this - > db - >,(“offer_promotion”,一些美元['名字']);