Jump to content


Photo

Busca Interna Com Filtro


  • Faça o login para participar
1 reply to this topic

#1 Sp3ak3

Sp3ak3

    12 Horas

  • Usuários
  • 151 posts
  • Sexo:Não informado

Posted 26/03/2009, 23:00

bom galerinha, estou tentando montar um sisteminha de busca simples aqui, mais to apanhando d+ pois ta dando erro:

olha o erro:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND atividade LIKE '%Criações e Internet%' AND cidade LIKE '%Anápolis%' AND seto' at line 1


codigo do form da busca:

<?php
include "includes/conecta.php";
$sql_atividade = mysql_query("select * from atividade", $db);
$sql_cidade = mysql_query("select * from cidade", $db);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.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>
<form action="busca.php" method="post" name="categoria">
<table width="100%" border="0">
<tr>
<td width="12%">Atividade:</td>
<td width="88%"><select name="atividade" id="categoria">
<option value="0">&lt;
<Selecione o tipo>
&gt;</option>
<?php while($array = mysql_fetch_array($sql_atividade)) {?>
<option value="<?php echo $array['1']; ?>"><?php echo $array['1']; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td>Cidade:</td>
<td><select name="cidade" id="atividade">
<option value="0">&lt;
<Selecione o tipo>
&gt;</option>
<?php while($array = mysql_fetch_array($sql_cidade)) {?>
<option value="<?php echo $array['1']; ?>"><?php echo $array['1']; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td>Setor:</td>
<td><input type="text" name="setor" id="setor" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Buscar" /></td>
</tr>
</table>
</form>
</body>
</html>


codigo do resultado da busca:

<?php
header("Content-Type: text/html; charset=ISO-8859-1", true);
require ("includes/conecta.php");
$sql_usu = "select id, empresa, atividade, cidade, setor from guia";
$atividade = $_POST['atividade'];
$cidade = $_POST['cidade'];
$setor = $_POST['setor'];
if($atividade || $cidade || $setor) {
$sql_usu .= " AND atividade LIKE '%$atividade%' AND cidade LIKE '%$cidade%' AND setor LIKE '%$setor%'";
}
$sql_usuarios = mysql_query($sql_usu) or die( mysql_error() );


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.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>
<?php
if (mysql_num_rows($sql_usuarios) > 0)
while ($vetor=mysql_fetch_array($sql_usuarios)) { ?>
<table width="100%" border="0">
<tr>
<td><?php echo $vetor['empresa'] ?></td>
</tr>
</table>
<?php } ?>
</body>
</html>


banco de dados:

create table atividade (
id int(11) not null auto_increment,
nome varchar(255) default null,
PRIMARY KEY(id)
);

create table cidade (
id int(11) not null auto_increment,
cidade varchar(255) default null,
PRIMARY KEY(id)
);

create table estado (
id int(11) not null auto_increment,
estado varchar(255) default null,
PRIMARY KEY(id)
);

create table guia (
id int(11) not null auto_increment,
empresa varchar(255) default null,
atividade varchar(255) default null,
cidade varchar(255) default null,
estado varchar(255) default null,
setor varchar(255) default null,
PRIMARY KEY(id)
);


quem puder me ajudar a fazer com que esta busca funcione beleza ficarei grata

#2 boirock

boirock

    Tecnologia para todos (agora hexa campeão)

  • Usuários
  • 1559 posts
  • Sexo:Masculino
  • Localidade:Curitiba - PR
  • Interesses:PostgreSQL - PHP

Posted 27/03/2009, 13:47

Se voce der um echo ao invés de executar a query, como ela fica exatamente?
Qual o erro exibido se executadno console ou phpmyadmin?




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq