Show DB information via combobox

Asked

Viewed 665 times

0

I’m a few days searching the internet and I don’t know if I’m looking the wrong way I just know I can’t find what I need.

Next: I would like to click on one of the options in the Combobox (or menu/list), which shows me the result below.

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

Could someone help me? I’m only using the PHP language, but if you need javascript if you can explain to me how to apply I’ll thank you very much.

NOTE: I don’t want to take the data that is in Mysql and put in Select. I want is that by clicking one of the options that is already in select I see below what is in Mysql.

I put this "OBS" because what I only found so far was how to fill the combobox and I want it is the opposite.

  • I think that that one and this other answer can help solve your problem. Take advantage and see how site works on tour.

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;
            ?>

Browser other questions tagged

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