Jump to content
Fórum Script Brasil
  • 0

Como fazer uma pagina de busca


Guilherme91

Question

7 answers to this question

Recommended Posts

  • 0

Criei esse aqui mas não consigo buscar:

<?php

// Recuperamos a ação enviada pelo formulário

$a = $_GET['a'];

// Verificamos se a ação é de busca

if ($a == "buscar") {

// Pegamos a palavra

$palavra = $_POST['palavra'];

// Verificamos no banco de dados produtos equivalente a palavra digitada

$sql = mysql_query("SELECT * FROM cadastro WHERE nome_func LIKE '%".$palavra."%' ORDER BY nome_func");

// Descobrimos o total de registros encontrados

$numRegistros = mysql_num_rows($sql);

// Se houver pelo menos um registro, exibe-o

if ($numRegistros != 0) {

// Exibe os produtos e seus respectivos preços

while ($x = mysql_fetch_array($sql)) {

echo'

<table width=0%" border="0" cellspacing="1" bgcolor="#9c9c9c">

<!--tr>

<td width="357" align="center" bgcolor="#FFFFFF"><strong><font color="#CD5C5C" size="1" face="verdana">...:::::Exibindo::::......</font> </strong></td>

</tr-->

<tr>

<td height="98" valign="top" bgcolor="#FFFFFF"> <table width="500" height="111" border="0" cellspacing="0">

<tr>

<td width="150"><strong><font size="1" face="verdana">Nome Funcionario:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['nome_func].'</font></td>

</tr>

<tr>

<td width="150"><strong><font size="1" face="verdana">Cargo:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['cargo'].'</font></td>

</tr>

<tr>

<td width=150"><strong><font size="1" face="verdana">Data de admissao:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['admissao].'</font></td>

</tr>

<tr>

<td width="44"><strong><font size="1" face="verdana">Servico:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['servicos'].'</font></td>

</tr>

<tr>

<td width=44"><strong><font size="1" face="verdana">Necessidade:</font></strong></td>

<td width="500"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['necessidade].'</font></td>

</tr>

<tr>

<td width="44"><strong><font size="1" face="verdana">Colaborador:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['colaborador'].'</font></td>

</tr>

<tr>

<td><strong><font size=1" face="verdana">Status:</font></strong></td>

<td><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['status].'</font></td>

</tr>

<tr>

<td width="44"><strong><font size="1" face="verdana">Data:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['data'].'</font></td>

<td width=314" align="right"><a href="excluir.php?id='.$x['id].'"><strong><font color="#828282" size="1" face="verdana">Deletar </font></strong> </a>&nbsp;&nbsp;<a href="alteracao.php?id='.$x['id'].'"><strong><font color="#828282" size="1" face="verdana"><form name="selecao">Editar</form> </font></form></strong></a></td>

</tr>

</tr>

</table></td>

</tr>

</table>

<br>

';

}

// Se não houver registros

} else {

echo "Nenhum nome foi encontrado com a palavra ".$palavra."";

}

}

?>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php"><font color="#cd5c5c" size="1" face="verdana">Pagina Inicial</font.></a></p>

</body>

</html>

Link to comment
Share on other sites

  • 0

Cara aparece a pagina normal.. Mas como criei um tabela para mostrar os dados que eu solicitei... Eles não esta retornando...

echo'

<table width="0%" border="0" cellspacing="1" bgcolor="#9c9c9c">

<!--tr>

<td width="357" align="center" bgcolor="#FFFFFF"><strong><font color="#CD5C5C" size="1" face="verdana">...:::::Exibindo::::......</font> </strong></td>

</tr-->

<tr>

<td height="98" valign="top" bgcolor="#FFFFFF"> <table width="500" height="111" border="0" cellspacing="0">

<tr>

<td width="150"><strong><font size="1" face="verdana">Nome Funcionario:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['nome_func'].'</font></td>

</tr>

<tr>

<td width=150"><strong><font size="1" face="verdana">Cargo:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['cargo].'</font></td>

</tr>

<tr>

<td width="150"><strong><font size="1" face="verdana">Data de admissao:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['admissao'].'</font></td>

</tr>

<tr>

<td width=44"><strong><font size="1" face="verdana">Servico:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['servicos].'</font></td>

</tr>

<tr>

<td width="44"><strong><font size="1" face="verdana">Necessidade:</font></strong></td>

<td width="500"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['necessidade'].'</font></td>

</tr>

<tr>

<td width=44"><strong><font size="1" face="verdana">Colaborador:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['colaborador].'</font></td>

</tr>

<tr>

<td><strong><font size="1" face="verdana">Status:</font></strong></td>

<td><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['status'].'</font></td>

</tr>

<tr>

<td width=44"><strong><font size="1" face="verdana">Data:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['data].'</font></td>

<td width="314" align="right"><a href="excluir.php?id='.$x['id'].'"><strong><font color=#828282" size="1" face="verdana">Deletar </font></strong> </a>&nbsp;&nbsp;<a href="alteracao.php?id='.$x['id].'"><strong><font color="#828282" size="1" face="verdana"><form name="selecao">Editar</form> </font></form></strong></a></td>

</tr>

</tr>

</table></td>

</tr>

</table>

<br>

';

Essa ai foi a tabela criada... Estou dando echo com os valores trazidos do banco... A pagina abre.. Mas os valores não vem.. Acho que a os codigos q estou utilizando não estao funcionando para buscar no banco.

Link to comment
Share on other sites

  • 0

<?php

// Recuperamos a ação enviada pelo formulário

$operacao = $_GET['operacao'];

// Verificamos se a ação é de busca

if ($operacao == "buscar") {

// Pegamos a palavra

$palavra = ($_GET['palavra'];

// Verificamos no banco de dados produtos equivalente a palavra digitada

$sql = mysql_query("SELECT * FROM cadastro WHERE nome_func LIKE '%$palavra%' ORDER BY nome_func");

// Descobrimos o total de registros encontrados

$numRegistros = mysql_num_rows($sql);

// Se houver pelo menos um registro, exibe-o

if ($numRegistros != 0) {

// Exibe os produtos e seus respectivos preços

while ($x = mysql_fetch_object($sql)) {

echo'

<table width=0%" border="0" cellspacing="1" bgcolor="#9c9c9c">

<!--tr>

<td width="357" align="center" bgcolor="#FFFFFF"><strong><font color="#CD5C5C" size="1" face="verdana">...:::::Exibindo::::......</font> </strong></td>

</tr-->

<tr>

<td height="98" valign="top" bgcolor="#FFFFFF"> <table width="500" height="111" border="0" cellspacing="0">

<tr>

<td width="150"><strong><font size="1" face="verdana">Nome Funcionario:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['nome_func].'</font></td>

</tr>

<tr>

<td width="150"><strong><font size="1" face="verdana">Cargo:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['cargo'].'</font></td>

</tr>

<tr>

<td width=150"><strong><font size="1" face="verdana">Data de admissao:</font></strong></td>

<td width="200"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['admissao].'</font></td>

</tr>

<tr>

<td width="44"><strong><font size="1" face="verdana">Servico:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['servicos'].'</font></td>

</tr>

<tr>

<td width=44"><strong><font size="1" face="verdana">Necessidade:</font></strong></td>

<td width="500"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['necessidade].'</font></td>

</tr>

<tr>

<td width="44"><strong><font size="1" face="verdana">Colaborador:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['colaborador'].'</font></td>

</tr>

<tr>

<td><strong><font size=1" face="verdana">Status:</font></strong></td>

<td><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['status].'</font></td>

</tr>

<tr>

<td width="44"><strong><font size="1" face="verdana">Data:</font></strong></td>

<td width="400"><strong><font color="#CD5C5C" size="1" face="verdana">'.$x['data'].'</font></td>

<td width=314" align="right"><a href="excluir.php?id='.$x['id].'"><strong><font color="#828282" size="1" face="verdana">Deletar </font></strong> </a>&nbsp;&nbsp;<a href="alteracao.php?id='.$x['id'].'"><strong><font color="#828282" size="1" face="verdana"><form name="selecao">Editar</form> </font></form></strong></a></td>

</tr>

</tr>

</table></td>

</tr>

</table>

<br>

';

}

// Se não houver registros

} else {

echo "Nenhum nome foi encontrado com a palavra ".$palavra."";

}

}

?>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php"><font color="#cd5c5c" size="1" face="verdana">Pagina Inicial</font.></a></p>

</body>

</html>

Agora esta me retornando que "Nenhum nome foi encontrado com a palavra ".$palavra.""

O que epode ser?

Ah coloquei com a conexao.php... Esqueci de colocar ai nesse codigo...

Mas da o mesmo problema...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...