Passing sql in CAKEPHP array input

Asked

Viewed 61 times

1

I need to make 3 queries, if x icon is enabled, make query X. If it is y icon, query y. If both are, I want everything from x and y query.

I can get the x and y query, but when it comes to getting everything from the 2 queries I cannot.

Ifs to check items.

 if(in_array('pacote',$criterios_pesquisa) && in_array('curso',$criterios_pesquisa)){
        $criterios['Curso.pacote '] = ? ;
    }
        if(in_array('pacote',$criterios_pesquisa)){
            $criterios['Curso.pacote'] = 1;
        }
        if(in_array('curso',$criterios_pesquisa)){
            $criterios['Curso.pacote !='] = 1;
        }

In my database the packets can be 1 or 0, as you see it was done, or take pacote = 1 or pacote != 1, I’m having trouble catching the 2.

@Edit

I did it that way and I managed to solve, if anyone has any 'more beautiful' method, feel free.

if(in_array('pacote',$criterios_pesquisa)){
            $criterios['Curso.pacote'] = 1;
        }
        if(in_array('curso',$criterios_pesquisa)){
            $criterios['Curso.pacote !='] = 1;
        }
        if(in_array('pacote',$criterios_pesquisa) && in_array('curso',$criterios_pesquisa)){
            unset($criterios['Curso.pacote']);
            unset($criterios['Curso.pacote !=']);
        }
  • Another way would be: https://ideone.com/dZR0Mf, I don’t know how your array criterios_pesquisa, so I don’t know if it’ll work for you.

No answers

Browser other questions tagged

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