[Resolvido] Busca não funciona ja tentei mais ta dificil
Ele exibe os dados na tela certinho, mais quando digito para buscar ele mostra o resultado da pesquisa e quantos dados foram achados, mais as informação não aparece na tela, apenas uma tabela fixa com todos os usuários cadastrados, preciso de ajuda muito obrigado!
<?php
include_once("conexao.php");
$filtro = isset($_GET['filtro'])?$_GET['filtro']:"";
$sql = "select * from usuarios where CPF like '%$filtro%' order by nome";
$consulta = mysqli_query($conexao,$sql);
$registros = mysqli_num_rows($consulta);
?>
<!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" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Alterar Cadastros123</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<?php
$parametro = filter_input(INPUT_GET, "parametro");
$mysqllink = mysqli_connect("localhost" , "root", "");
mysqli_select_db($mysqllink, "cadastro");
if ($parametro){
$dados = mysqli_query("select * from usuarios where nome like '$parametro%' order by CPF");
}else
{
$dados = mysqli_query($mysqllink, "select * from usuarios order by CPF");
}
$linha = mysqli_fetch_assoc($dados);
$total = mysqli_num_rows($dados);
?>
</head>
<body>
<center>
<p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
</p>
<h1>Consultas</h1>
<hr><br><br>
<form method="get" action="">
Busca por CPF:: <input type="text" name="filtro" class="campo" required= autofocus>
<input type="submit" value="Pesquisar" class="btn">
</form>
<?php
$filtro = isset($_GET['filtro'])?$_GET['filtro']:"";
$sql = "select * from usuarios where CPF like '%$filtro%' order by CPF";
$consulta = mysqli_query($conexao,$sql);
$registros = mysqli_num_rows($consulta);
print "Resultado da pesquisa com o número <strong>$filtro</strong>.<br><br>";
print "$registros Registros encontrado(s).";
print "<br><br>";
while($registros = mysqli_fetch_array($consulta)){
$codigo = $registros[0];
$CPF = $registros[8];
$nome = $registros[0];
$sobrenome = $registros[1];
$pais = $registros[2];
$estado = $registros[3];
$cidade = $registros[4];
$email = $registros[5];
$senha = $registros[6];
}
?>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>CPF</th>
<th>nome</th>
<th>sobrenome</th>
<th>pais</th>
<th>estado</th>
<th>cidade</th>
<th>email</th>
<th>senha</th>
<th></th>
</tr>
</thead>
</tbody>
<?php
if ($total) { do {
?>
<tr>
<td><?php echo $linha['id'] ?></td>
<td><?php echo $linha['CPF'] ?></td>
<td><?php echo $linha['nome'] ?></td>
<td><?php echo $linha['sobrenome'] ?></td>
<td><?php echo $linha['pais'] ?></td>
<td><?php echo $linha['estado'] ?></td>
<td><?php echo $linha['cidade'] ?></td>
<td><?php echo $linha['email'] ?></td>
<td><?php echo $linha['senha'] ?></td>
<td><a href="<?php echo "paginaalterar.php?id=" . $linha['id'] . "&CPF" . $linha['CPF'] . "&nome" . $linha['nome'] . "&sobrenome" . $linha['sobrenome'] . "&pais" . $linha['pais'] . "&estado" . $linha['estado'] . "&cidade" . $linha['cidade'] . "&email" . $linha['email'] . "&senha" . $linha['senha']?>">Alterar</td>
</tr>
<?php
} while ($linha = mysqli_fetch_assoc($dados));
mysqli_free_result($dados);}
mysqli_close($mysqllink);
?>
</td>
</tbody>
</table>
</div>
</center>
</tbody>
<center>
<a href="cadastrousuario.php" button type="button" class="btn btn-success">Cadastrar</button></a>
<a href="alteradadocliente.php" button type="button" class="btn btn-danger">Excluir Cliente</button></a>
<a href="consultas.php" button type="button" class="btn btn-primary">Consulta</button></a>
</center>
</html>Discussão (15)
Carregando comentários...