Filtro com chekbox mysql php


Could you help me how I would concatenate strings in this search, passing which table is right if it would be ai or c?

select i.nome from imovel i join cidade c
where c.nome in ("Campo Grande","Paranaíba")
and i.tipo in ("Casa","Apartamento")
and i.dormitorio in ("4","5")

function parseMysqlQuery($array) {

    $output = '';
    foreach ($array as $key => $value) {
        $output .= !$output ? " WHERE $table.$key " : " AND $table.$key";
        $output .= ' IN ("' . implode('","', $value) . '")';
    echo "Key: $key; Value: $value<br />\n";
    return $output;

$array = (array)filter_input_array(INPUT_POST,
        array( 'num' =>
                 array( 'filter' => FILTER_SANITIZE_STRING,
                        'flags' => FILTER_FORCE_ARRAY),
                        'grupo'  => array(
                            'filter' => FILTER_SANITIZE_STRING,
                            'flags'  => FILTER_FORCE_ARRAY,
                        'dt_de_inducao' => array(
                            'filter' => FILTER_SANITIZE_STRING,
                            'flags'  => FILTER_FORCE_ARRAY,

//SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'folha_tarefa' if ($_SERVER['REQUEST_METHOD'] == "POST") { $array = array_filter($array);

$in = parseMysqlQuery($array);

$query = "SELECT * FROM contratos " . $in;.

This is a filter with checkbox, but I have a search that makes a left join and I'm not able to make my php understand which table to search, ex nametable.columnname


It looks like $table.$key would be nome_tabela.campo and $value the table value, so the correct thing would be to pass an array structure similar to this format:

$table = 'imovel';

$arrIn = array(
           array('c.nome'=> array('Campo Grande','Paranaíba')),
           array('i.tipo'=> array('Casa','Apartamento')),
           array('i.dormitorio'=> array('4','5'))
$in = parseMysqlQuery($arrIn);

$query = "select i.nome from {$table} i join cidade c on(c.id_cidade=i.id_fk_cidade)
where c.nome " . $in;
Scroll to Top