How to get an entry in codeigniter where a clause using json values
My question is my table stores json encoded values like
field Name : offer_promotion
[{"name":"sample promotion","price":"1555","expdate":"2017-05-15","shortdesc":"test","longdesc":"test"}]
Now I want to write a query to select records, for example For eaxmple:
$this->db->where('offer_promotion', "name":"sample promotion");
How do I write this request?
+3
Karthik Saravanan
source
to share
2 answers
json in the database works like a simple string. So you have to apply line-like logic. You can use Like
$this->db->like('offer_promotion', '%"name":"sample promotion"%');
+3
Aniket singh
source
to share
-
$some = json_decode($json);
-
$this->db->where('offer_promotion',$some['name']);
+1
Exprator
source
to share