Search id returned from json_encode () inside mysql

0

I have the following content in the field pro_are_id : ["11","3"] this content made with json_encode() , I would like to query the database and know if this id exists in specific or not, I tried this way:

$area = 1;
$this->db->like("pro_are_id", $area);
return $this->db->get('produto')->result();

The problem with this method is that it will return true, because there is 11, which contains the number 1 (id I am searching for).

What would be the correct way to get the result? Can not I just use WHERE?

Note: I am using codeigniter, but if the answer is in PHP, I can use it within CI guidelines.

    
asked by anonymous 16.05.2017 / 02:33

2 answers

0

I got the solution as follows:

$area = 1;
$this->db->like("pro_are_id", json_encode($area));
return $this->db->get('produto')->result();

Passing json_encode () from the $ area, returns me only if I have the registry ... It does not look right, but here it worked perfectly. Unless there is another logic that works best.

    
18.05.2017 / 02:24
-1

From what I saw in the documentation, try to use:

$this->db->get_where('produto', array('pro_are_id', 1))->result();

Not being% $this->db->like("pro_are_id", $area);

    
16.05.2017 / 17:58