user_777
user_777

Reputation: 805

where condition for json_encode value stored in database

My value stored in the database looks like this ["7","8"] and i want to check if my search value is present in it for that i had used my code like this

       $this->db->where_in(json_decode('tool_id'),$tool_id);
       $this->db->where('status',0);
       $query=$this->db->get('tbl_tools_supplied');
       return $query->result();

my all values are stored like this in tool_id column here its not getting the output so is there any other way

Upvotes: 1

Views: 558

Answers (2)

Geomi George
Geomi George

Reputation: 51

This works for me

SELECT * FROM table_name WHERE FIND_IN_SET("7", REPLACE(REPLACE(tool_id,'[', ''), ']',''))

Upvotes: 1

Harry baldaniya
Harry baldaniya

Reputation: 167

you can not search your id in where condition of sql query if column store data as json,but you can fetch all records and then filter out result array of mysql query by match your id.

Upvotes: 0

Related Questions