4

My question is in my table stored 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 query for select records like, For eaxmple:

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

How to write this query?

1

2 Answers 2

3

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

$this->db->like('offer_promotion', '%"name":"sample promotion"%');
Sign up to request clarification or add additional context in comments.

1 Comment

@KarthikSaravanan, Welcome in SO. This link may be helpful for you stackoverflow.com/help/someone-answers
1
  1. $some = json_decode($json);
  2. $this->db->where('offer_promotion',$some['name']);

1 Comment

How can we use php code ` json_decode($json)` in query?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.