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

时间:2017-05-15 11:46:45

标签: php mysql json codeigniter

我的问题是在我的表中存储了json编码的值 field Name : offer_promotion

 [{"name":"sample promotion","price":"1555","expdate":"2017-05-15","shortdesc":"test","longdesc":"test"}]

现在我想为选择记录编写查询,比如 对于eaxmple:

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

如何撰写此查询?

2 个答案:

答案 0 :(得分:3)

数据库中的json作为一个简单的字符串。 所以你必须应用类似于字符串的逻辑。 你可以使用Like

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

答案 1 :(得分:1)

  1. $some = json_decode($json);
  2. $this->db->where('offer_promotion',$some['name']);