Filter Select elements with PHP

1

I have to create a select filter to perform a search between multiple select results

<divclass="grupo">
<!-- class="borda select2_single form-control comboauto" -->
    <select name="id_projeto" id="id_projeto" class="borda select2_single form-control ">
        <option value="">Selecione</option>
        <?php 
            foreach (ProjetoModel::retorna(" order by descricao") as $obj) { 
        ?>
            <option value="<?php echo $obj->getid() ?>" 

            <?php echo $obj->getid()==$vObject->getidProjeto()?'selected':'' ?>>
            <?php echo $obj->titulo; ?>
            </option>
        <?php } ?>
    </select>
</div>

Returnfunction

publicstaticfunctionretorna($extra='',$vWhere=null){$arr=array();$sql='SELECT*FROMprojetowhere1=1';$sql.=self::getWhere($vWhere);$sql.=$extra;$vResult=Conexao::getInstance()->query($sql);while($vResult&&$obj=$vResult->fetchObject()){$arr[]=newClassProjeto($obj->id,$obj->titulo,$obj->descricao,$obj->id_net,$obj->id_trafo);}return$arr;}

JAVASCRIPT

<script type="text/javascript">
    var config = {
      '.chosen-select'           : {},
      '.chosen-select-deselect'  : {allow_single_deselect:true},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
      '.chosen-select-width'     : {width:"95%"}
    }
    for (var selector in config) {
      $(selector).chosen(config[selector]);
    }
  </script>
    
asked by anonymous 14.08.2017 / 19:06

1 answer

1
<div class="grupo">
<!-- class="borda select2_single form-control comboauto" -->
<select name="id_projeto" id="id_projeto" class="borda select2_single form-control ">
    <option value="">Selecione</option>
    <?php 
        foreach (ProjetoModel::retorna(" order by descricao", " where coluna = termo ") as $obj) { 
    ?>
        <option value="<?php echo $obj->getid() ?>" 

        <?php echo $obj->getid()==$vObject->getidProjeto()?'selected':'' ?>>
        <?php echo $obj->titulo; ?>
        </option>
    <?php } ?>
</select>
</div>

Return function:

public static function retorna($extra='', $vWhere=null) {
    $arr=array();
    $sql = 'SELECT * FROM projeto ';
    $sql .= $vWhere;
    $sql .= $extra;
    $vResult = Conexao::getInstance()->query($sql);
        while($vResult && $obj = $vResult->fetchObject()) {
            $arr[] = new ClassProjeto($obj->id, $obj->titulo, $obj->descricao, $obj->id_net, $obj->id_trafo);
        }
        return $arr;
}

Make sure you enter the column and term within the foreach. If you want more filters and only use and , ex: where coluna = termo and coluna2 = termo2

    
14.08.2017 / 19:39