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

Adicionando campos na busca


mistermind

Pergunta

estou fazendo um site, mais gostaria de colocar uma busca por palavras , já tem 3 , cidade , agentes e tipos , como faço pra funcionas essa busca de textfield junto com as outras

olhem ai

<? require_once("busca_principal.php");?>

<form method=POST action="busca_avancada.php">

<div align="left">

</div>

<table width=100% align=center bgcolor="#F4F4F4">

<tr>

<td width="99"> <p>

não FUCIONA ESSA BUSCA

<input name="busca" type="text" id="busca" />

COMO que FA&Ccedil;O PRA FUNCIONAR

</p>

<p><br>

</p> </td>

</tr>

<tr>

<td><p><strong>Em:</strong><br>

<?=$CityMenu?>

</p>

<p>

<?=$AgentsMenu?>

</p>

<p>

<?=$TypeMenu?>

</p></td>

</tr>

<tr>

<td height="25">

<input type=submit name=s1 value="Buscar"></td>

</tr>

</table>

</form>

</div></td>

</tr>

<tr>

<td><p>

<?=$Account?>

<?=$Categories?>

</p></td>

</tr>

</table></td>

<td width="564" valign="top"><div align="center">

<table width="491" height="100%" border="0" cellpadding="0" cellspacing="0">

<tr>

<td width="479"><div align="center"></div></td>

</tr>

<tr>

<td height="100%"><div align="center">

<p>

Link para o comentário
Compartilhar em outros sites

5 respostass a esta questão

Posts Recomendados

  • 0

Sobre a dúvida você pode adaptar um código pronto do próprio SB (Script Brasil). É muito fácil. Procura lá que você consegue ;'). É uma solução válida xD...

Valeu

Fui!

Editado por Therak
Link para o comentário
Compartilhar em outros sites

  • 0
Em primeiro lugar onde está a parte do código que pesquisa de fato?

Em segundo lugar, basicamente, se for em um banco de dados é colocar AND campo='$dados_do_form'

essa e da pagina busca principal.php

<?
require_once("configuracao_mysql.php");

if(isset($_POST[s1]))
{
if(!empty($_POST[cat]))
{
$CatInfo = explode("|", $_POST[cat]);

$c = $CatInfo[0];

if($CatInfo[1] > '0')
{
$s = $CatInfo[1];
}
}

if(!empty($_POST[search_country]))
{
$search_country = $_POST[search_country];
}

if(!empty($_POST[search_state]))
{
$state = $_POST[search_state];
}

if(!empty($_POST[search_city]))
{
$search_city = $_POST[search_city];
}

if(!empty($_POST[search_PropertyType]))
{
$search_PropertyType = $_POST[search_PropertyType];
}

if(!empty($_POST[MinPrice]))
{
$MinPrice = $_POST[MinPrice];
}

if(!empty($_POST[MaxPrice]))
{
$MaxPrice = $_POST[MaxPrice];
}

if(!empty($_POST[MinRooms]))
{
$rooms1 = $_POST[MinRooms];
}

if(!empty($_POST[MaxRooms]))
{
$rooms2 = $_POST[MaxRooms];
}

if(!empty($_POST[MinBath]))
{
$bath1 = $_POST[MinBath];
}

if(!empty($_POST[MaxBath]))
{
$bath2 = $_POST[MaxBath];
}

if(!empty($_POST[AgentID]))
{
$agent = $_POST[AgentID];
}

if(!empty($_POST[old]))
{
$before = $_POST[old];
}

if(!empty($_POST[NearSchool]))
{
$school = $_POST[NearSchool];
}

if(!empty($_POST[NearTransit]))
{
$transit = $_POST[NearTransit];
}

if(!empty($_POST[NearPark]))
{
$park = $_POST[NearPark];
}

if(!empty($_POST[OceanView]))
{
$ocean_view = $_POST[OceanView];
}

if(!empty($_POST[LakeView]))
{
$lake_view = $_POST[LakeView];
}

if(!empty($_POST[MountainView]))
{
$mountain_view = $_POST[MountainView];
}

if(!empty($_POST[OceanWaterfront]))
{
$ocean_waterfront = $_POST[OceanWaterfront];
}

if(!empty($_POST[LakeWaterfront]))
{
$lake_waterfront = $_POST[LakeWaterfront];
}

if(!empty($_POST[RiverWaterfront]))
{
$river_waterfront = $_POST[RiverWaterfront];
}

$url = "buscador.php?c=$c&s=$s&search_country=$_POST[search_country]&search_state=$_POST[search_state]&search_city=$_POST[search_city]&search_PropertyType=$_POST[search_PropertyType]&MaxPrice=$MaxPrice&MinPrice=$MinPrice&rooms1=$rooms1&rooms2=$rooms2&bath1=$bath1&bath2=$bath2&AgentID=$agent&before=$before&school=$school&transit=$transit&park=$park&ocean_view=$ocean_view&lake_view=$lake_view&mountain_view=$mountain_view&ocean_waterfront=$ocean_waterfront&lake_waterfront=$lake_waterfront&river_waterfront=$river_waterfront";

header("location:$url");
exit();
}

require_once("includes.php");
/*
//create the category menu
$CategoryMenu = "<select name=cat>\n\t<option value=\"\"></option>\n\t";

$q1 = "select * from re2_categories order by CategoryName";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
while($a1 = mysql_fetch_array($r1))
{
$CategoryMenu .= "<option value=\"$a1[CategoryID]|0\">$a1[CategoryName]</option>\n\t";

//get the subcategories
$q2 = "select * from re2_subcategories where CategoryID = '$a1[CategoryID]' order by SubcategoryName ";
$r2 = mysql_query($q2) or die(mysql_error());

while($a2 = mysql_fetch_array($r2))
{
$CategoryMenu .= "<option value=\"$a1[CategoryID]|$a2[SubcategoryID]\">$a1[CategoryName] - $a2[SubcategoryName]</option>\n\t";
}

}
}

$CategoryMenu .= "</select>\n";

*/
//create the state menu
$StateMenu = "<select name=search_state>\n\t<option value=\"\">Todos os Estados</option>\n\t";

$q1 = "select distinct state from re2_listings order by state";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
while($a1 = mysql_fetch_array($r1))
{
$StateMenu .= "<option value=\"$a1[state]\">$a1[state]</option>\n\t";
}
}

$StateMenu .= "</select>\n";

//create the city menu
$CityMenu = "<select name=search_city>\n\t<option value=\"\">Todas as Cidades</option>\n\t";

$q1 = "select distinct city from re2_listings order by city";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
while($a1 = mysql_fetch_array($r1))
{
$CityMenu .= "<option value=\"$a1[city]\">$a1[city]</option>\n\t";
}
}

$CityMenu .= "</select>\n";


//create the country menu
$CountryMenu = "<select name=search_country>\n\t<option value=\"\">Todos os países</option>\n\t";

$q1 = "select distinct country from re2_listings order by country";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
while($a1 = mysql_fetch_array($r1))
{
$CountryMenu .= "<option value=\"$a1[country]\">$a1[country]</option>\n\t";
}
}

$CountryMenu .= "</select>\n";

//create the PropertyType menu
$TypeMenu = "<select name=search_PropertyType>\n\t<option value=\"\">Todos os tipos</option>\n\t";

$q1 = "select distinct PropertyType from re2_listings order by PropertyType";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
while($a1 = mysql_fetch_array($r1))
{
$TypeMenu .= "<option value=\"$a1[PropertyType]\">$a1[PropertyType]</option>\n\t";
}
}

$TypeMenu .= "</select>\n";


//create the Price Minimum menu
$MinPrice = "<select name=MinPrice>\n\t<option value=\"\">Mínimo</option>\n\t";

$q1 = "select distinct Price from re2_listings order by Price asc";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
while($a1 = mysql_fetch_array($r1))
{
$prices .= "<option value=\"$a1[Price]\">R$ $a1[Price]</option>\n\t";
}
}

$MinPrice .= $prices."</select>\n";


//create the max price menu
$MaxPrice = "<select name=MaxPrice>\n\t<option value=\"\">Máximo</option>\n\t";
$MaxPrice .= $prices."</select>\n";

//bedrooms
$MinBed = "<select name=MinRooms>\n\t<option value=\"\">Mínimo</option>\n\t";

for($i = '0'; $i <= '20'; $i++)
{
$bed .= "<option value=\"$i\">$i</option>\n\t";
}

$MinBed .= $bed."</select>\n";

$MaxBed = "<select name=MaxRooms>\n\t<option value=\"\">Máximo</option>\n\t";
$MaxBed .= $bed."</select>\n";

//bathrooms
$MinBath = "<select name=MinBath>\n\t<option value=\"\">Mínimo</option>\n\t";

for($i = '0'; $i <= '10'; $i++)
{
$bath .= "<option value=\"$i\">$i</option>\n\t";
}

$MinBath .= $bath."</select>\n";

$MaxBath = "<select name=MaxBath>\n\t<option value=\"\">Máximo</option>\n\t";
$MaxBath .= $bath."</select>\n";

//agents menu
$q1 = "select AgentID, FirstName, LastName from re2_agents order by FirstName, LastName";
$r1 = mysql_query($q1) or die(mysql_error());

$AgentsMenu = "<select name=AgentID>\n\t<option value=\"\">Todos os agentes</option>\n\t";

if(mysql_num_rows($r1) > '0')
{
while($a1 = mysql_fetch_array($r1))
{
$AgentsMenu .= "<option value=\"$a1[AgentID]\">$a1[FirstName] $a1[LastName]</option>\n\t";
}
}

$AgentsMenu .= "</select>\n";


?>[/codebox]

Link para o comentário
Compartilhar em outros sites

  • 0

Usa o codebox para não quebrar o layout do fórum... bom, você tem que seguir padrão do script...

if(!empty($_POST[jnome_do_campo]))
{
$variavel_nova = $_POST[nome_do_campo];
}

$url = "buscador.php?c=$c&s=$s&search_country=$_POST[search_country]&search_state=$_POST[search_state]&search_city=$_POST[search_city]&search_PropertyType=$_POST[search_PropertyType]&MaxPrice=$MaxPrice&MinPrice=$MinPrice&rooms1=$rooms1&rooms2=$rooms2&bath1=$bath1&bath2=$bath2&AgentID=$agent&before=$before&school=$school&transit=$transit&park=$park&ocean_view=$ocean_view&lake_view=$lake_view&mountain_view=$mountain_view&ocean_waterfront=$ocean_waterfront&lake_waterfront=$lake_waterfront&river_waterfront=$river_waterfront&algumcoisa=$variavel_nova";

header("location:$url");
exit();[/codebox]

Nessa página: buscador.php

Você tem que pegar esse novo parâmetro que foi passado e jogar na query...

Link para o comentário
Compartilhar em outros sites

  • 0

ESTE CODEBOX DA DANDO ERRO AI...VAI AQUI MESMO...DESCULPA AI AMIGO, TA T ENCOMODANDO, beleza...SO QUERO RESOLVE ESSA BUSCA

FICO ASSIM NO BUSCADOR.PHP , SERÁ ISSO, DEIXEI O MESMO NOME que você COLOCOU, depois altero

<?

require_once("configuracao_mysql.php");

require_once("includes.php");

$query = array();

if(!empty($_POST[jnome_do_campo]))

{

$variavel_nova = $_POST[nome_do_campo];

}

$url = "buscador.php?c=$c&s=$s&search_country=$_POST[search_country]&search_state=$_POST[search_state]&search_city=$_POST[search_city]&search_PropertyType=$_POST[search_PropertyType]&MaxPrice=$MaxPrice&MinPrice=$MinPrice&rooms1=$rooms1&rooms2=$rooms2&bath1=$bath1&bath2=$bath2&AgentID=$agent&before=$before&school=$school&transit=$transit&park=$park&ocean_view=$ocean_view&lake_view=$lake_view&mountain_view=$mountain_view&ocean_waterfront=$ocean_waterfront&lake_waterfront=$lake_waterfront&river_waterfront=$river_waterfront&algumcoisa=$variavel_nova";

header("location:$url");

exit();

if(!empty($_GET[c]))

{

$query[] = "re2_listings.CategoryID = '$_GET[c]' ";

}

if(!empty($_GET))

{

$query[] = "re2_listings.SubcategoryID = '$_GET' ";

}

E NO PRIMEIRA PAGINA COLOCO O NOME NO TEXTFIELD

<? require_once("busca_principal.php");?>

<form method=POST action="busca_avancada.php">

<div align="left">

</div>

<table width=100% align=center bgcolor="#F4F4F4">

<tr>

<td width="99"> <p>

não FUCIONA ESSA BUSCA

<input name="nome_do_campo" type="text" id="nome_do_campo" />

COMO que FA&Ccedil;O PRA FUNCIONAR

</p>

<p><br>

</p> </td>

</tr>

<tr>

<td><p><strong>Em:</strong><br>

<?=$CityMenu?>

</p>

<p>

<?=$AgentsMenu?>

</p>

<p>

<?=$TypeMenu?>

</p></td>

Editado por mistermind
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,1k
    • Posts
      651,8k
×
×
  • Criar Novo...