Search and List through Json_decode

Asked

Viewed 40 times

0

I have the following tables: inserir a descrição da imagem aqui

When doing the brand search through the input post, I need to list all products that contain the selected brand id. Below is my passage.

$marca = $this->input->post('marca');
$marca  = explode(',', $marca);

if (count($marca) > 0) {
            $i = 0;
            foreach ($marca as $row) {
                $i++;


    if ($row !== "") {
             if ($row !== "0") {
              $query[] = $row;
              $this->db->where_in(' marca_id ', $query);

                    } 
            }
}       
 }

With this section only list if in the field marca_id has an integer number, I know I have to use the function json_decode, but I can’t get the expected result.

  • $marca has json? what is its structure?

  • In this case the $brand does not yet have the json

  • No, I need to go through the tag fields and check if there is the id of the selected tag. if there should be a product

  • Then the json and the $i nothing related to the question? just do the direct consultation at the bank then

  • exact, but how to verify tag ids within the tag?

  • 1

    Could you alter this bank structure? I believe it would be "but appropriate" to work with a single value in the marca_id field, i.e., avoid "multivariate" columns. Otherwise, you will have to return all the column records, go through a loop and fetch the ID, this may cost more in computational terms. Otherwise, a "Gambi" would be you give a like by = "%'id'%"

  • 1

    in fact, I had already done using two tables where I do relationship by Ids, but I thought using only one table would be easier...

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.