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

Problema com resultado de pesquisa interna!


Raio da Noite

Pergunta

Estou com dois problemas para pesquisa interna em meu site, a pesquisa é feita por meio de um textfield e um combobox, escolhendo assim a categoria especifica que quer buscar, categorias estas que a combobox traz do banco de dados bom o problema:

Primeiro um campo especifico no select que vem da tabela do banco não deveria aparecer o restante sim, ou seja todas as categorias menos a categoria que tem o nome geral, e ele está me trazendo todas as categorias pra buscar!

Segundo aparentemente ele está buscando corretamente informando os valores de quantos produtos achou conforme os existentes nas categorias respectivas, porém ele não exibe estes produtos, fica em branco depois das mensagens pré definidas por mim

alguém pode dar uma ajuda? Obrigado desde já!

Segue os codigos:

MENU.PHP:

<?php 
$id_cat = $_GET["id_cat"]; 
$id_subcat = $_GET["id_subcat"]; 
?> 
<!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=iso-8859-1" /> 
<title>Festas e Alegorias tudo para Festas de &Eacute;poca - Menu</title> 
<style type="text/css"> 
<!-- 
body { 
margin-top: 0px; 
} 
.style1 { 
font-family: Arial, Helvetica, sans-serif; 
font-size: 9px; 
} 
--> 
</style></head> 

<body> 
<table width="188" border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td colspan="3">&nbsp;</td> 
</tr> 
<tr> 
<td colspan="3"><div align="center"><img src="img/bot_produtos.png" width="187" height="39" /></div></td> 
</tr> 
<tr> 
<td colspan="3">&nbsp;</td> 
</tr> 
<tr> 
<td width="7"> 
<div align="left"></div></td> 
<td width="171"><?php $sql_cat = mysql_query("SELECT * FROM categorias"); 
while($coluna_cat = mysql_fetch_array($sql_cat)) { 
if ($coluna_cat[id_categoria] !=1) 
echo "<a href = \"index.php?link=2&id_cat=$coluna_cat[id_categoria]\"> 
$coluna_cat[categoria] </a> <br>"; 
if ($id_cat ==$coluna_cat[id_categoria]) 
{ 
$sql_subcat = mysql_query("SELECT * FROM subcategorias WHERE id_categoria='$id_cat'"); 
while($coluna_subcat = mysql_fetch_array($sql_subcat)) { 
echo "- <a href = \"index.php?link=2&id_cat=$coluna_subcat[id_categoria]&id_subcat=$coluna_subcat[id_subcategoria]\">$coluna_subcat[subcategoria] </a> <br>"; 
} 
} 
} 
?></td> 
<td width="10">&nbsp;</td> 
</tr> 
<tr> 
<td colspan="3">&nbsp;</td> 
</tr> 
<tr> 
<td colspan="3"><div align="center"><img src="img/linha.png" width="187" height="4" /></div></td> 
</tr> 
<tr> 
<td colspan="3">&nbsp;</td> 
</tr> 
<tr> 
<td colspan="3"><form id="form1" name="form1" method="POST" action="index.php?link=3"> 
<div align="center" class="style1">Digite um produto para buscar:</br> 
<label> 
<input name="txt_valor" type="text" id="txt_valor" size="25" /> 
</label></br> 
<label> 
<br /> 
<select name="txt_cat" id="txt_cat"> 
<option value ="">Todas as Categorias</option> 
<?php $sql = mysql_query("SELECT * FROM categorias ORDER BY categoria"); 
while ($coluna = mysql_fetch_array($sql)) { ?> 
<option value="<?php echo $coluna[id_categoria] ?>"<?php if ($coluna[id_categoria]==$txt_cat) echo "selected"; ?>> 
<?php echo $coluna[categoria]; ?></option> 
<?php } ?> 
</select> 
<input type="image" name="imageField" src="img/pesquisar.png" /> 
</label> 
</div> 
</form> </td> 
</tr> 
</table> 
</body> 
</html>
BUSCA.PHP
<?php 
$txt_valor = $_POST["txt_valor"]; 
$i = $_GET['i']; 
$txt_cat = $_POST["txt_cat"]; 
?> 
<!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=iso-8859-1" /> 
<title>Untitled Document</title> 
</head> 

<body> 
<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td><table width="100%" border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td>Resultado da Pesquisa:</td> 
</tr> 
<tr> 
<td><img src="img/linha2.png" width="660" height="4" /></td> 
</tr> 
<?php 
if ($txt_cat!="") 
$tem_categoria = "AND id_categoria='$txt_cat'"; 
$sql_geral = mysql_query("SELECT * FROM produtos WHERE produto LIKE '%".$txt_valor."%' order by id_produto Desc"); 

$qtde_produtos = mysql_num_rows($sql_geral); 
$i = 0; 
?> 
<tr> 
<td>Foram encontrados <i><?php echo $qtde_produtos ?></i> resultados para sua pequisa de Produto(s) com a palavra <i><?php echo $txt_valor ?></i>:</td> 
</tr> 
<tr> 
<td><img src="img/linha2.png" width="660" height="4" /></td> 
</tr> 
<tr> 
<?php if ($qtde_produtos == 0) { ?> 
<td>Nenhum Produto encontrado com <i><?php echo $txt_valor ?></i></td> 
<? } else { ?> 
</tr> 
<tr> 
<td><table width="100%" border="0" cellspacing="0" cellpadding="4"> 
<tr> 
<?php 
while ($i < $qtde_produtos) 
{ 
?> 
<td width="50%" align="center"><table width="100%" border="1" cellspacing="0" cellpadding="0"> 
<tr> 
<td><?php echo "<img src = admin/img/produto/".@mysql_result($sql_geral,$i,foto)." border =2 width=75 align= left>"; ?> 
<b> <p align="center"> <?php echo @mysql_result($sql_geral,$i,produto); ?> <b> 

</p> 

</p></td> 
</tr> 
<tr> 
<td align="center"><form action="" method="post"> 
<label> 
<input type="image" name="imageField" src="img/comprar.png" /> 
</label> 
<label> 
<input type="image" name="imageField2" src="img/detalhes.png" /> 
</label> 
</form></td> 
</tr> 
</table></td> 
<?php $i++; 
if ($i%2==0) 
echo "</tr>"; 
} ?> 
</table> 
<?php } ?> 
</td> 
</tr> 
</table></td> 
</tr> 
</table> 
</body> 
</html>

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

Troca:

<?php
while ($i < $qtde_produtos)
{
?>
<td width="50%" align="center"><table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td><?php echo "<img src = admin/img/produto/".@mysql_result($sql_geral,$i,foto)." border =2 width=75 align= left>"; ?>
<b> <p align="center"> <?php echo @mysql_result($sql_geral,$i,produto); ?> <b>

</p>

</p></td>
</tr>
<tr>
<td align="center"><form action="" method="post">
<label>
<input type="image" name="imageField" src="img/comprar.png" />
</label>
<label>
<input type="image" name="imageField2" src="img/detalhes.png" />
</label>
</form></td>
</tr>
</table></td>
<?php $i++;
if ($i%2==0)
echo "</tr>";
} ?>
Por:
<?php
while ($produtos = mysql_fetch_assoc($sql_geral))
{
print_r($produtos);
?>
<td width="50%" align="center"><table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td><?php echo "<img src = admin/img/produto/".$produtos['foto']." border =2 width=75 align= left>"; ?>
<b> <p align="center"> <?php echo $produtos['produto']; ?> <b>

</p>

</p></td>
</tr>
<tr>
<td align="center"><form action="" method="post">
<label>
<input type="image" name="imageField" src="img/comprar.png" />
</label>
<label>
<input type="image" name="imageField2" src="img/detalhes.png" />
</label>
</form></td>
</tr>
</table></td>
<?php $i++;
if ($i%2==0)
echo "</tr>";
} ?>

O print_r ali é pra exibir tudo que está vindo na query, se estiver em branco então a query tem problemas...

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...