Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

beowlf

[Resolvido] Formulario de pesquisa

Recommended Posts

Bom dia Pessoal...

 

tenho um novo desafio :D

 

eu tenho esse formulario que você coloca os dados e ele busca as informacoes

 

vo postar o campos tbm do formulario

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
	<link rel="stylesheet" type="text/css" href="/css/style_admin.css"/>
       <title>Pesquisar Atendimento</title>
   </head>

   <body>
       <h3>Pesquisar Atendimento </h3><br />
      <form action="inc/pesquisarAtendimento.php" method="post">

<fieldset>
			<label><span>Id:</span> <input name="id" type="text" disabled="disabled"/> </label>
			<label><span>Data do Atendimento:</span> <input name="data_atendimento" type="text" /> </label>
               <label><span>Data do Acidente:</span> <input name="data_acidente" type="text" /> </label>
			<label><span>Numero do Sinistro:</span> <input name="num_sinistro" type="text" /> </label>

               <label><span>Nome da Vitíma:</span> <input type="text" size="50" name="nome" /></label>
			 <label><span>Assunto:</span><select name="assunto" >
			  <option>Selecione</option>
			  <option>01 - Morte</option>
			  <option>02 - IPA/Invalidez</option>
			  <option>03 - Dams</option>
			  <option>04 - Invalidez Total</option>
			  <option>Dams - Complemento</option></select></label>
			  <label><span>Funcionário:</span><select name="funcionario" >
			  <option>Selecione</option>
			  <option>Fabiano Mancuzo</option>
			  <option>Regina Martinez</option>
			  <option>Claudinei Martinez </option>
			  <option>Gabriel Sabadini </option>
			  <option>Solange Martinez</option></select></label>
			<label><span>Situação do Cadastro:</span><select name="situacao">
			<option>Selecione</option>
			<option>Em Aberto</option>
			<option>Pendente</option>
			<option>Cancelado</option>
			<option>Concluido</option></select></label>	                  
               <label><span>Valor da Indenização:</span>  <input type="text" size="20" name="valor_total" /> </label>

                   <div class="div"><input type="submit" value="Pesquisar" name="pesquisar" />
				<input type="submit" value="Voltar" name="Voltar" /></div>

       </fieldset>
       </form>
       <p> </p>
   </body>
</html>

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="/css/style_admin.css"/>
       <title>Pesquisar Atendimento</title>
   </head>

   <body>
       <h3>Relatório Atendimento</h3><br />

       <?php
       //incluir arquivo de conexao com o banco de dados
       include_once ('conexao.php');

       //receber dados vindos do formulário
       $ID       = $_POST['id'];
	$DATA = $_POST['data_atendimento']; 
	$DATAACIDENTE = $_POST['data_acidente'];
	$NUMSINISTRO = $_POST['num_sinistro'];
	$NOME = $_POST['nome'];
	$ASSUNTO = $_POST['assunto'];
	$FUNCIONARIO = $_POST['funcionario'];
	$SITUACAO = $_POST['situacao'];  
	$VALORTOTAL = $_POST['valor_total'];
       $botao          = $_POST['Voltar'];

       //verifica qual botao foi clicado
       if ($botao == 'Voltar') {
           echo '<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=/admin.php">';
       } else {

            //monta comando SQL para incluir o registro
           $sql = "SELECT * FROM cad_atendimento WHERE 1=1";
           if(!empty ($DATA)){
               $sql .= " AND   data_atendimento        =	'{$DATA}' ";
           }
		 if(!empty ($DATAACIDENTE)){
               $sql .= " AND   data_acidente        =	'{$DATAACIDENTE}' ";
           }
		 if(!empty ($NUMSINISTRO)){
               $sql .= " AND   num_sinistro        =	'{$NUMSINISTRO}' ";
           }
           if(!empty ($NOME)){
               $sql .= " AND     nome        LIKE      '%{$NOME}%' ";
           }
           if(!empty ($ASSUNTO)){
           $sql .= " AND     assunto     LIKE 	'%{$ASSUNTO}%' ";
           }
           if(!empty ($FUNCIONARIO)){
           $sql .= " AND     funcionario     LIKE 	'%{$FUNCIONARIO}%' ";
           }
		if(!empty ($SITUACAO)){
           $sql .= " AND     situacao     LIKE 	'%{$SITUACAO}%' ";
           }
		if(!empty ($VALORTOTAL)){
           $sql .= " AND     valor_total     LIKE 	'%{$VALORTOTAL}%' ";
           }
           $sql .= " ORDER BY nome,data_atendimento ASC";

           //executa a query
           $query = mysql_query($sql)or die(mysql_error());
       ?>
           <table width="900" border="1" cellspacing="0" cellpadding="0">
               <tr>
				<td width="50" height="30"><strong>ID</strong></td>
                   <td width="150" height="30"><strong>Data Atendimento</strong></td>
				<td width="150" height="30"><strong>Data Acidente</strong></td>
				<td width="200" height="30"><strong>Numero do Sinistro</strong></td>
				<td width="450" height="30"><strong>Nome da Vitíma</strong></td>
				<td width="200" height="30"><strong>Assunto</strong></td>
				<td width="347" height="30"><strong>Funcionário</strong></td>
				<td width="200" height="30"><strong>Situação</strong></td>
				<td width="150" height="30"><strong>Valor Indenização</strong></td>
				<td width="320"><strong><img src="/images/new.png" title="Novo Serviço">  <img src="/images/alterar.png" title="Alterar">  <img src="/images/delete.png" title="Excluir">  <img src="/images/detail.png" title="Detalhes"> </strong></td>
               </tr>
           <?php
           //percorre resultado no resultado 
           while ($linha = mysql_fetch_array($query))
           {
               echo '<tr>';
			echo '  <td>' . $linha['id'] . '</td>';
			echo '  <td>' . $linha['data_atendimento'] . '</td>';
			echo '  <td>' . $linha['data_acidente'] . '</td>';
			echo '  <td>' . $linha['num_sinistro'] . '</td>';
			echo '  <td>' . $linha['nome'] . '</td>';
			echo '  <td>' . $linha['assunto'] . '</td>';
			echo '  <td>' . $linha['funcionario'] . '</td>';
			echo '  <td>' . $linha['situacao'] . '</td>';
			echo '  <td>' . $linha['valor_total'] . '</td>';
               echo '  <td>
		<a href="formNovoServico.php?id=' . $linha['id'] . '"><img src="/images/new.png" title="Novo Serviço"></a>
		<a href="formAlterarAtendimento.php?id=' . $linha['id'] . '"><img src="/images/alterar.png" title="Alterar"></a>
		<a href="formExcluirAtendimento.php?id=' . $linha['id'] . '"><img src="/images/delete.png" title="Excluir"></a>
		<a href="detalheAtendimento.php?id=' . $linha['id'] . '"><img src="/images/detail.png" title="Detalhes"></a></td>';
               echo '</tr>';
           }
           ?>
       </table>
       <p><a href="/admin.php?pg=inc/formPesquisarAtendimento.php" style="font:14px; border:1px solid #ccc; padding:5px;">Voltar</a></p>
        <?php } ?>
   </body>
</html>

 

ja revisei o codigo muitas vezes ele ate pesquisa mas so traz oq esta esta cadastrado em branco quando você coloca alguma informacao ele traz a busca vazia

 

nao sei mais oq pode ser por isso postei aqui...

 

Valeu gente Obrigado!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

   echo $sql;
   $query = mysql_query($sql)or die(mysql_error());

 

faça uma busca, e nos informe oque retorna desse echo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

quando escrevo alguma coisa ou seleciono

ele traz vazia a pesquisa nao da erro e quando eu clico em pesquisar sem nada selecionado ou escrito ele traz os cadastros que estao no banco vazio

tipo vo anexar uma imagem

 

problema.png

 

Obrigado!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

ok, mas responda oque eu perguntei.

 

eu pedi o resultado do echo, qndo você faz uma pesquisa.

Depois disso podemos prosseguir.

Compartilhar este post


Link para o post
Compartilhar em outros sites

SELECT * FROM cad_atendimento WHERE 1=1 AND assunto LIKE '%Selecione%' AND funcionario LIKE '%Selecione%' AND situacao LIKE '%Selecione%' ORDER BY nome,data_atendimento ASC

 

olha a mensagem que deu...

 

SELECT * FROM cad_atendimento WHERE 1=1 AND nome LIKE '%Fabiano%' AND assunto LIKE '%Selecione%' AND funcionario LIKE '%Selecione%' AND situacao LIKE '%Selecione%' ORDER BY nome,data_atendimento ASC

 

esse é quando eu digitei meu nome na pesquisa...

Compartilhar este post


Link para o post
Compartilhar em outros sites

troque as suas condições, para o seguinte:

if(!empty ($ASSUNTO) && $ASSUNTO!='Selecione' ){

entendeu?

 

faça com as demais condições. Se tiver dúvidas, poste o script. E também o echo, depois dessa alteração.

 

Uma forma melhor, que eu sugiro, é trabalhando com arrays:

http://wbruno.com.br/blog/2011/05/28/formulario-de-busca-filtro-dinamico-em-mysql-php/

Compartilhar este post


Link para o post
Compartilhar em outros sites

pqp fico show demais muito obrigado.....

 

 

$sql = "SELECT * FROM cad_atendimento WHERE 1=1";
           if(!empty ($DATA)&& $DATA!='Selecione' ){
               $sql .= " AND   data_atendimento        =	'{$DATA}' ";
           }
		 if(!empty ($DATAACIDENTE) && $DATAACIDENTE!='Selecione' ){
               $sql .= " AND   data_acidente        =	'{$DATAACIDENTE}' ";
           }
		 if(!empty ($NUMSINISTRO) && $NUMSINISTRO!='Selecione' ){
               $sql .= " AND   num_sinistro        =	'{$NUMSINISTRO}' ";
           } 
           if(!empty ($NOME)&& $NOME!='Selecione' ){
               $sql .= " AND     nome        LIKE      '%{$NOME}%' ";
           }
		if(!empty ($ASSUNTO) && $ASSUNTO!='Selecione' ){
           $sql .= " AND     assunto     LIKE 	'%{$ASSUNTO}%' ";
           }
           if(!empty ($FUNCIONARIO) && $FUNCIONARIO!='Selecione' ){
           $sql .= " AND     funcionario     LIKE 	'%{$FUNCIONARIO}%' ";
           }
		if(!empty ($SITUACAO) && $SITUACAO!='Selecione' ){
           $sql .= " AND     situacao     LIKE 	'%{$SITUACAO}%' ";
           }
		if(!empty ($VALORTOTAL) && $VALORTOTAL!='Selecione' ){
           $sql .= " AND     valor_total     LIKE 	'%{$VALORTOTAL}%' ";
           }
           $sql .= " ORDER BY nome,data_atendimento ASC";

 

o codigo fico assim perfeito....

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.