Ir para conteúdo
Fórum Script Brasil
  • 0

Busca avançada Menu DropDown


Pedro Vanderlan Santana

Pergunta

Olá pessoal,

 

 

Venho humildemente pedir ajuda, estou criando um sistema e gostaria que fosse feita a pesquisa por um sistema de menus em DropDown.

A busca seria em um banco mysql.
Abaixo vou postar o código de como eu faço as pesquisas hoje.

 

Por exemplo se eu quiser pesquisar as obras por STATUS ou Por FISCAL como seria isso no código PHP? 

Como eu passaria os  parametro para a query do mysql?

 

 

<?php

        require_once ("../conecta.php");
        //SOMA OBRAS E PESQUISA
        $sql = "SELECT * FROM controle WHERE status='ANDAMENTO' AND fiscal='PEDRO'";
        $resultado = mysql_query($sql) or die("Não foi possível realizar a consulta ao banco de dados");

        $somaobras = mysql_query("SELECT * FROM controle WHERE status = 'ANDAMENTO' AND fiscal='PEDRO'");
        $totalobras = @mysql_num_rows($somaobras);

        //SOMA POSTE
        $pesquisaposte = mysql_query("SELECT sum(poste) FROM controle where status = 'ANDAMENTO' AND fiscal='PEDRO'");
        while($sum = mysql_fetch_array($pesquisaposte)){
            $somaposte = $sum['sum(poste)'];
        }
        //SOMA CLIENTES
        $pesquisaclientes = mysql_query("SELECT sum(consumidores) FROM controle where status = 'ANDAMENTO' AND fiscal='PEDRO'");
        while($sum = mysql_fetch_array($pesquisaclientes)){
            $somaclientes = $sum['sum(consumidores)'];
        }

        //totalizar valores
        $pesquisahisto = mysql_query("SELECT sum(custohisto) as custohisto FROM controle WHERE status = 'ANDAMENTO' AND fiscal='PEDRO'");
        $sum = mysql_fetch_array($pesquisahisto);
        $somahisto = $sum['custohisto'];

        $pesquisaproj = mysql_query("SELECT sum(custoproj) as custoproj FROM controle WHERE status = 'ANDAMENTO' AND fiscal='PEDRO'");
        $sum = mysql_fetch_array($pesquisaproj);
        $somaproj = $sum['custoproj'];


        //SOMA CLIENTES
        //$pesquisacustohisto = mysql_query("SELECT SUM(REPLACE((SELECT REPLACE(custohisto,'.','')),',','.')) FROM controle");
        //while($sum = @mysql_fetch_array($pesquisacustohisto)){
        //  $somacustohisto = $sum['sum(custohisto)'];
        //}




        //            SELECT SUM(REPLACE((SELECT REPLACE(valor_compra,'.','')),',','.')) FROM  compras WHERE id_prod = '25'







        echo "<table class='table table-hover table-striped table-bordered'>

           <thead>
           <tr>
           <th nowrap><h4 align='center'>Projeto</h4></th>
           <th nowrap><h4 align='center'>Nota</h4></th>
           <th nowrap><h4 align='center'>Título</h4></th>
           <th nowrap><h4 align='center'>Município</h4></th>
           <th nowrap><h4 align='center'>Fiscal</h4></th>
           <th nowrap><h4 align='center'>Poste</h4></th>
           <th nowrap><h4 align='center'>Clientes</h4></th>
           <th nowrap><h4 align='center'>Custo Proj</h4></th>
           <th nowrap><h4 align='center'>Data Cont</h4></th>
           <th nowrap><h4 align='center'>Prazo</h4></th>
           <th nowrap><h4 align='center'>SI</h4></th>
           <th nowrap><h4 align='center'>Data SI</h4></th>
           <th nowrap><h4 align='center'>Custo Hist</h4></th>
           <th nowrap><h4 align='center'>Prioridade</h4></th>
           <th nowrap><h4 align='center'>Status</h4></th>
           </tr>
           </thead>";


        while ($linha = mysql_fetch_array($resultado)) {
            $id = $linha["id"];
            $projeto = $linha["projeto"];
            $expediente = $linha["expediente"];
            $titulo = $linha["titulo"];
            $municipio = $linha["municipio"];
            $fiscal = $linha["fiscal"];
            $poste = $linha["poste"];
            $consumidores = $linha["consumidores"];
            $custoproj = number_format($linha["custoproj"],2,",",".");
            $datacontratacao = $linha["datacontratacao"];
            $prazoobra = $linha["prazoobra"];
            $dataenergi = $linha["dataenergi"];
            $si = $linha["si"];
            $datasi = $linha["datasi"];
            $datapasta = $linha["datapasta"];
            $concdefinicao = $linha["concdefinicao"];
            $custohisto = number_format($linha["custohisto"],2,",",".");
            $prioridade = $linha["prioridade"];
            $status = $linha["status"];


            echo "<tr>

                <th nowrap><span style= 'font-size: 12px';>B$projeto</th>
                <th nowrap><span style= 'font-size: 12px';>$expediente</th>
                <th nowrap><span style= 'font-size: 12px; align: center';>$titulo</th>
                <th nowrap><span style= 'font-size: 12px';>$municipio</th>
                <th nowrap><span style= 'font-size: 12px';>$fiscal</th>
                <th nowrap><span style= 'font-size: 12px; display: block; margin: 0px auto; text-align: center';>$poste</th>
                <th nowrap><span style= 'font-size: 12px; display: block; margin: 0px auto; text-align: center';>$consumidores</th>
                <th nowrap><span style= 'font-size: 12px';>R$ $custoproj</th>
                <th nowrap><span style= 'font-size: 12px';>$datacontratacao</th>
                <th nowrap><span style= 'font-size: 12px';>$prazoobra</th>
                <th nowrap><span style= 'font-size: 12px';>$si</th>
                <th nowrap><span style= 'font-size: 12px';>$datasi</th>
                <th nowrap><span style= 'font-size: 12px';>R$ $custohisto</th>
                <th nowrap><span style= 'font-size: 12px';>$prioridade</th>
                <th nowrap><span style= 'font-size: 12px';>$status</th>";
            echo  "</tr>";
        }

        echo "</table>";
        echo "<p>";
        echo "<p>";


        $somahisto1 = number_format($somahisto,2,",",".");
        $somaproj1 = number_format($somaproj,2,",",".");

        echo "<h4>Obras :<span style='color: red';> $totalobras</h4>"; echo "<h4>Postes :<span style='color: red';> $somaposte</h4>"; echo "
<h4>Clientes :<span style='color: red';> $somaclientes</h4>";
        echo "<h4>Custo Proj.:<span style='color: red';>R$ $somaproj1</h4>";
        echo "<h4>Custo Histo.:<span style='color: red';>R$ $somahisto1</h4>";
        ?>
</div>

 

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Fiz algo parecido com o que pretendes.

No entanto, atenção que vais ter de rever os totais porque não ficaram a funcionar correctamente. Como o código é extenso, fica o link para o PasteBin. Espero que ajude.
Já agora, considera utilizar MySQLi ou PDO em vez da extensão mysql para aceder à base de dados.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...