Show DB information via combobox

0

I'm looking for a few days on the internet and I do not know if I'm looking for the wrong way, I just know that I can not find what I need.

Next: I would like to click on one of the options that is in the ComboBox (or menu / list), which would show me the result just below.

Example: I have a ComboBox with priority "High", "Medium", "Low" and "All". As soon as I click on one of these options below it immediately shows me the results according to what I clicked and that is registered in Mysql.

Can anyone help me? I am using the PHP language only, but if you need javascript if you can explain how to apply I will thank you very much.

NOTE: I do not want to get the data that is in Mysql and by the Select. I want to be that by clicking on one of the options that is already in the select I visualize below what is in Mysql.

I put this "OBS" because what I just found so far was how to fill the combobox being that I want is the opposite.

    
asked by anonymous 22.05.2015 / 03:26

1 answer

1
//Funções utilizadas

function conectar_banco_mysql(){
    $dsn = "mysql:host=localhost;dbname=seu_bd";
    $username = "root";
    $passwd = "";
    $pdo = new PDO($dsn, $username, $passwd);
    return $pdo;    
}

function listarCategorias($tabela) {
    $pdo = conectar_banco_mysql();
    $listar = $pdo->query("select distinct categoria from $tabela ORDER BY categoria ASC ");
    $dados_encontrados = $listar->fetchALL(PDO::FETCH_OBJ); 
    return $dados_encontrados;
}


<form method="post" action="">
                <h3>Busca</h3>
                <h4>Categorias</h4>
                <input  type="hidden" name="local" value="" />
                <select class="input1" type="text" size="7" style="width:600px; background-color: #fff; color:#000; padding-left: 15px;" name="categoria" >
                    <?php
                    $categorias_encontradas = listarCategoria("nome_sua_tabela");
                    if (!empty($categorias_encontradas)):
                        foreach ($categorias_encontradas as $local):
                            // print_r($local);
                            ?>                          
                            <option value="<?php echo $local->categoria ?>"><?php echo $local->categoria ?>    
                                <?php
                            endforeach;
                        else:
                            ?>
                            Nenhuma entrada para processar!
                        <?php
                        endif;
                        ?>
                </select><br><br>

                <div class="botonstop">
                <input class="btn btn-success" type="submit" value="pesquisar">
                </div>
            </form>       
            <?php
            @$busca = filter_var($_POST['categoria'], FILTER_SANITIZE_MAGIC_QUOTES);
// print_r($busca);
            if (!empty($_POST['categoria'])): //para obter o nome da categoria           
                $tarefas_encontradas = listarBusca('sua_tabela', $busca);
                foreach ($tarefas_encontradas as $caixa):
                    //  print_r($caixa);
                    ?> 
<!--Exemplo do relatório-->
                    <div class="post">                    
                        Tarefa n&#186  <?php echo $caixa->id_coluna_tabela; ?> |                     
                        Projeto n&#186 <?php echo $caixa->num_projeto_coluna_tabela; ?><br>
                        Data agendada: <?php echo $caixa->data_alvo_coluna_tabela; ?><br>
                        Última atualização:  <?php echo $caixa->data_coluna_tabela; ?><br>
                        <div>Categoria: <?php echo $caixa->categoria_coluna_tabela; ?></div><br>
                        Resumo: 
                        <div class="descrresum"><?php echo $caixa->titulo_resumido_coluna_tabela; ?></div><br>
                        Descrição:
                        <div  class="descrdescr"><?php echo $caixa->hist_coluna_tabela; ?></div><br>                        
                        <div class="botons">
                        <input class="btn btn-mini btn-info" type="button" VALUE="► Editar" onclick="location.href = '?p=actplan_alter&id=<?php echo $caixa->id; ?>';">
               <?php
                endforeach;
                ?>
                <?php
            else:
                echo '<h3 style="color: orange;">Nenhuma categoria selecionada!</h3> <h6 style="color:red;">Selecione <span style="color: black;">CLASSIFICAR</span> para ver tarefas sem categoria';
            endif;
            ?>
    
23.05.2015 / 01:06