Jump to content


Photo

Sistema De Busca


  • Faça o login para participar
3 replies to this topic

#1 gajowebmaster

gajowebmaster

    Novato no fórum

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

Posted 27/10/2008, 11:42

pessoal to com um problema no sistema de busca as palavras com mens de tres letras não aparece na primeira pagina so nas ultimas ....

[codebox]<?php

include( 'adm/config.php');

include( 'adm/lampiao.php');

include( 'adm/class/class.enquete.php');

include( 'adm/class/class.enquetee.php');

include( 'adm/class/class.banners.php');

include_once( "adm/funcoes.php");

$lampiao = new Lampiao();



$in = mysql_query("SELECT * FROM canais where id = '$idd' and lixo='n' and disp='s'") or die("Erro SQL: ".mysql_error());

while ($inl=mysql_fetch_array($in)) {

$canal = $inl["canal"];

}

if($canal == "") { $canal = "paginicial"; }

$banner = new Banner("$canal");

$campobusca2 = trim( $campobusca);

$campobusca2= strtolower($campobusca2);

$campobusca3 = ",".$campobusca.",";

$campobusca = trim( $campobusca);

$campobusca = str_replace(" "," +","$campobusca");

$campobusca = "+".$campobusca;

if($campobusca == "") {

echo("&lt;script>alert(\"O campo busca não foi preenchido.\"); window.location = 'java script:history.back(-1)'; </script>");

}

elseif(strlen($campobusca)<=1){

echo("&lt;script>alert(\"O campo busca precisa ter mais de 1 caracteres.\"); window.location = 'java script:history.back(-1)'; </script>");

}

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR...nsitional.dtd">

<!-- saved from url=(0014)about:internet -->

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>index.jpg</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">

td img {display: block;}body {

background-color: #E8E8E8;

margin-left: 0px;

margin-top: 0px;

margin-right: 0px;

margin-bottom: 0px;

}

.style1 {

font-family: Arial, Helvetica, sans-serif;

font-size: 17px;

font-weight: bold;

}

.style4 {

font-family: Arial, Helvetica, sans-serif;

font-size: 12px;

}

.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 18px; font-weight: bold; }

.style11 {font-family: Arial, Helvetica, sans-serif; font-size: 11px; }

.style15 {

font-family: Arial, Helvetica, sans-serif;

font-size: 12px;

font-weight: bold;

color: #0000FF;

}

.style6 {font-size: 12px; color: #000000; font-family: Arial, Helvetica, sans-serif;}

.style3 { font-size: 28px;

font-family: Arial, Helvetica, sans-serif;

font-weight: bold;

}

</style>

<!--Fireworks 8 Dreamweaver 8 target. Created Sat Aug 02 02:19:37 GMT-0300 (Hora oficial do Brasil) 2008-->

</head>

<body>

<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">

<!-- fwtable fwsrc="index.png" fwbase="index.jpg" fwstyle="Dreamweaver" fwdocid = "1479144753" fwnested="0" -->

<tr>

<td><img src="imagens/spacer.gif" width="10" height="1" border="0" alt="" /></td>

<td><img src="imagens/spacer.gif" width="148" height="1" border="0" alt="" /></td>

<td><img src="imagens/spacer.gif" width="94" height="1" border="0" alt="" /></td>

<td><img src="imagens/spacer.gif" width="215" height="1" border="0" alt="" /></td>

<td><img src="imagens/spacer.gif" width="246" height="1" border="0" alt="" /></td>

<td><img src="imagens/spacer.gif" width="10" height="1" border="0" alt="" /></td>

<td><img src="imagens/spacer.gif" width="1" height="1" border="0" alt="" /></td>

</tr>
<tr>

<td colspan="6" rowspan="5"><table border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td>&nbsp;</td>

<td align="center" bgcolor="#FEFEFE"><table width="703" border="0" cellpadding="0" cellspacing="0">

<tr>

<td width="703" height="134" align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macr...rsion=7,0,19,0" width="703" height="134">
<param name="movie" value="banner.swf" />
<param name="quality" value="high" />
<embed src="banner.swf" quality="high" pluginspage="http://www.macromedi...getflashplayer" type="application/x-shockwave-flash" width="709" height="134"></embed>
</object></td>
</tr>

</table></td>

<td>&nbsp;</td>

</tr>

</table></td>

<td><img src="imagens/spacer.gif" width="1" height="6" border="0" alt="" /></td>

</tr>

<tr>

<td><img src="imagens/spacer.gif" width="1" height="31" border="0" alt="" /></td>

</tr>

<tr>

<td><img src="imagens/spacer.gif" width="1" height="1" border="0" alt="" /></td>

</tr>

<tr>

<td><img src="imagens/spacer.gif" width="1" height="24" border="0" alt="" /></td>

</tr>

<tr>

<td><img src="imagens/spacer.gif" width="1" height="27" border="0" alt="" /></td>

</tr>

<tr>

<td>&nbsp;</td>

<td colspan="4" align="center" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="77" align="center">

<table width="95%" height="59" border="0" cellpadding="0" cellspacing="0">

<tr>

<form id="form1" name="form1" method="post" action="resultado.php"><td align="left"><table width="436" height="48" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC" background-repeat="no repeat" >
<tr>
<td width="324" align="right"><div align="right">
<input name="campobusca" type="text" id="campobusca" style="width:300px" />
</div></td>
<td width="107" align="left"><input name="image" type="image" src="imagens/pesq.gif" align="left" width="70" height="21" /></td>
</tr>
</table></td>
</form>
</tr>
</table>

<table width="95%" height="26" border="0" cellpadding="0" cellspacing="0">

<tr>

<td height="26" class="style1">Resultados da busca </td>

</tr>

</table>

<table width="95%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="22"><span class="style4">A busca por <strong><?=$campobusca2;?></strong> resultou <?

$numero=strlen($campobusca2);

if($campobusca2 == "disk gas" or $campobusca2 == "disk gás") {

$bi = ",gas,";

$sqlrop = mysql_query("SELECT * from cad WHERE palavras REGEXP '$bi'");

}

elseif($numero > 3) {

//SE HA UMA FRASE SE UTILIZA O ALGORTIMO DE BUSCA AVANCADO DE MATCH AGAINST

//busca de frases com mais de uma palavra e um algoritmo especializado

$sqlrop = mysql_query("SELECT * , MATCH ( nome, categoria1, palavras ) AGAINST ( '$campobusca' IN BOOLEAN MODE) AS Score FROM cad WHERE MATCH ( nome, categoria1, palavras ) AGAINST ( '$campobusca' IN BOOLEAN MODE) ORDER BY nivel DESC, Score DESC");

} elseif($numero < 4) {

$sqlrop = mysql_query("SELECT * from cad WHERE palavras REGEXP '$campobusca3'");

}
$rego = mysql_num_rows($sqlrop);

?><?=$rego;?> registro(s).</span></td>

</tr>

</table>

<table width="98%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="10"><table width="120" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="6"><img src="imagens/spacer.gif" width="1" height="10" /></td>

</tr>

</table></td>

</tr>

</table></td>

</tr>

</table>

<table width="95%" height="291" border="0" cellpadding="0" cellspacing="0">

<tr>

<td width="100%" height="291" valign="top">



<?php



//CONTA O NUMERO DE PALAVRAS

$numero=strlen($campobusca2);



if($campobusca2 == "disk gas" or $campobusca2 == "disk gás") {

$bi = ",gas,";

$sqlrop = mysql_query("SELECT * from cad WHERE palavras REGEXP '$bi' order by nivel desc");

}

elseif($numero > 3) {

//SE HA UMA FRASE SE UTILIZA O ALGORTIMO DE BUSCA AVANCADO DE MATCH AGAINST

//busca de frases com mais de uma palavra e um algoritmo especializado

$sqlrop = mysql_query("SELECT * , MATCH ( nome, categoria1, palavras,telefone ) AGAINST ( '$campobusca' IN BOOLEAN MODE) AS Score FROM cad WHERE MATCH ( nome, categoria1, palavras,telefone) AGAINST ( '$campobusca' IN BOOLEAN MODE) and (tipo!='Pessoa Física') ORDER BY nivel DESC, Score DESC");

}

elseif($numero < 4) {

$sqlrop = mysql_query("SELECT * from cad WHERE palavras REGEXP '$campobusca3' order by nivel desc");

}



?>



<?



$lpp = 10; // Especifique quantos resultados voc&ecirc; quer por p&aacute;gina

$total = mysql_num_rows($sqlrop); // Esta fun&ccedil;&atilde;o ir&aacute; retornar o total de linhas na tabela

$paginas = ceil($total / $lpp); // Retorna o total de p&aacute;ginas

if(!isset($pagina)) { $pagina = 1; }

else { $paginaa = $pagina - 1; }// Especifica uma valor para variavel pagina caso a mesma n&atilde;o esteja setada

$inicio = $paginaa * $lpp; // Retorna qual ser&aacute; a primeira linha a ser mostrada no MySQL



//CONTA O NUMERO DE PALAVRAS

$numero=strlen($campobusca2);

if($campobusca2 == "disk gas" or $campobusca2 == "disk gás") {

$bi = ",gas,";

$sqlrop = mysql_query("SELECT * from cad WHERE palavras REGEXP '$bi' order by nivel desc LIMIT $inicio, $lpp");

}

elseif($numero > 3) {



//SE HA UMA FRASE SE UTILIZA O ALGORTIMO DE BUSCA AVANCADO DE MATCH AGAINST

//busca de frases com mais de uma palavra e um algoritmo especializado

$sqlrop = mysql_query("SELECT * , MATCH ( nome, categoria1, palavras ) AGAINST ( '$campobusca' IN BOOLEAN MODE) AS Score FROM cad WHERE MATCH ( nome, categoria1, palavras ) AGAINST ( '$campobusca' IN BOOLEAN MODE) and (tipo!='Pessoa Física') ORDER BY Nivel desc, Score DESC LIMIT $inicio, $lpp");

}



elseif($numero < 4) {

$sqlrop = mysql_query("SELECT * from cad WHERE palavras REGEXP '$campobusca3' order by nivel desc LIMIT $inicio, $lpp");

}




$i=0;


while ($resultado =mysql_fetch_object($sqlrop))



{

$_score = $resultado->Score;

$_tipo = $resultado->tipo;

$_id = $resultado->id;

$_desc1 = $resultado->desc1;

$_site = $resultado->site;

$_nivel = $resultado->nivel;

$_telefone = $resultado->telefone;

$_bairro = $resultado->bairro;

if ($_bairro != "") { $_bairrro = "/"." $_bairro"; }

$_endereco = $resultado->endereco;

$_nivel = $resultado->nivel;

if($_nivel == "Nível 04" or $_nivel == "Nível 05") {

$_imagemlogo = $resultado->imagemlogo;

}else {
$_imagemlogo = $resultado->imagenlogo=("");

}

$_palavras = $resultado->palavras;

$_data = $resultado->data;

$_data = implode(preg_match("~\/~", $_data) == 0 ? "/" : "-", array_reverse(explode(preg_match("~\/~", $_data) == 0 ? "-" : "/", $_data)));

$_disp = $resultado->disp;

$_nome = $resultado->nome;

$_email = $resultado->email;

$_categoria1 = $resultado->categoria1;

$_categoria2 = $resultado->categoria2;

$_categoria3 = $resultado->categoria3;

$_categoria4 = $resultado->categoria4;

$_categoria5 = $resultado->categoria5;

$endereco = "imagens/".$_imagemlogo;

?>

<table cellpadding="0" cellspacing="0" <? if($_nivel == "Nível 05") { ?> bgcolor="#EFEFEF" <? } ?> style="border:solid; border:1px; border-color:#999999; border-style:solid;">

<tr>

<td><table width="100%" border="0" cellpadding="8" cellspacing="0" >

<tr>

<td width="340" valign="top"><span class="style5">

<? echo"$_nome";?>

</span> <br />

<span class="style11">

<?=$_desc1;?>

</span>

<table width="98%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="13"><img src="imagens/spacer.gif" width="1" height="13" /></td>

</tr>

</table>

<table width="98%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="13"><span class="style11">

<?=$_endereco;?>

<? echo $_bairrro; ?>

/ Indaiatuba/SP</span></td>

</tr>

</table>

<table width="98%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="13"><span class="style11">Telefones:<strong>

<?=$_telefone;?>

</strong></span></td>

</tr>

</table>

<table width="98%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="23"><span class="style15">+

<? if($_site != "") {?>

<a href="<?=$_site;?>" target="_blank">Site</a> /

<? } if($_email != "") {?>

<a href="mailto:<?=$_email;?>" target="_blank">Email</a> /

<? }?><a href="map.php?idm=<?=$_id;?>">Mapa</a></span> </td>

</tr>
</table></td>
<td width="101" valign="top"><table width="120" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="6"><img src="imagens/spacer.gif" width="1" height="4" /></td>
</tr>

</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="26"><? if ($_imagemlogo != "") { ?>

<? if ($_site != "")

{ ?> <a href="<?=$_site;?>" target="_blank" style="color:#999999"> <? } ?>

<img src="imagemdim.php?aa=120&amp;imagem=<? echo "$endereco"; ?>" border="1" style="border-color:#999999"></a>

<? } ?></td>

</tr>

</table></td>

</tr>

</table></td>

</tr>

</table>

<table width="98%" border="0" cellpadding="0" cellspacing="0">

<tr>

<td height="20"><img src="imagens/spacer.gif" width="1" height="13" /></td>

</tr>

</table>

<?

$i++;

}





?>

<table width="93%" border="0" cellpadding="0" cellspacing="0">

<tr>

<td><? if ($total > $lpp) { ?>

<table width="614" height="30%" border="0" cellpadding="0" cellspacing="0">

<tr>

<td align="left" class="style6"><? if ($total > $lpp) { ?>

<?

// Agora o mais importante, gera os links....



if ($pagina > 1) {

$menos = $pagina - 1;

$url = "$PHP_SELF?pagina=$menos&campobusca=$campobusca&tipo=$tipo";

print "<a href=\"$url\" style='text-decoration:none; color:#000000'>&lt; Anterior</a>&nbsp;";

} else {

print "&lt; Anterior&nbsp;";

}

?>

<? for($i = 1; $i <= $paginas; $i++) {

$em = $em + 1;

if ($pagina == $i) {

if ($em == "1") { print " <b>$i</b>"; }

elseif ($em != "1") {

print " | <b>$i</b>";

}

} else {

$url = "$PHP_SELF?pagina=$i&campobusca=$campobusca&tipo=$tipo";

if ($em == "1") { print " <a href=\"$url\" style='text-decoration: none;color:#000000'>$i</a>"; }

elseif ($em != "1") {

print " | <a href=\"$url\" style='text-decoration: none;color:#000000'>$i</a>";

}

}

}

?><?

// Agora o mais importante, gera os links....

if ($pagina <= ($paginas - 1)) {

$mais = $pagina + 1;

$url = "?pagina=$mais&campobusca=$campobusca&tipo=$tipo";

print "&nbsp;<a href=\"$url\" style='text-decoration:none;color:#000000'>Pr&oacute;xima &gt;</a>";

} else {

print "&nbsp;Pr&oacute;xima &gt;";

}

?><? } ?></td>

</tr>

</table>

<? } ?></td>

</tr>

</table>

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

<tr>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;</td>

</tr>

<tr>

<td>&nbsp;</td>

</tr>

</table></td></tr>

</table></td>

<td>&nbsp;</td>

<td><img src="imagens/spacer.gif" width="1" height="149" border="0" alt="" /></td>

</tr>

</table>

</body>

</html>[/codebox]

Edição feita por: gajowebmaster, 28/10/2008, 08:05.


#2 Alaerte

Alaerte

    Novato no fórum

  • Usuários
  • 11 posts
  • Sexo:Masculino
  • Localidade:Itabuna-BA
  • Interesses:Programação: PHP / MySQL / SQL Server/ HTML / CSS / JavaScript / XML / VB /

    Sistemas: Windows Server / Linux

Posted 27/10/2008, 12:54

Olá, será que você poderia ser mais claro ?

utilize as tags CODE para por seu código, fica mais limpo e agiliza uma resposta para você.
Refrigere minha alma, guia-me pelo caminho da justiça "Salmo 23 cap 3"
WebMaster/Designer - Desenvolvedor Web - TI
Alaerte Gabriel ou ガブリエル
Visitem >> http://www.webaplicacoes.com/

#3 gajowebmaster

gajowebmaster

    Novato no fórum

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

Posted 28/10/2008, 07:23

seguinte ....quando peu faço uma busca por " francisco automoveis " ...esse resultado aparece na primeiro pagina ..... mas quando busco um que tem um apalavra com menos de tres letras tipo " jb veiculos " a pagina de registro busca varios outros registro que tem a palavra veiculos ....entam o jb veiculos acaba aparecendo nas ultimas paginas de resultado ...... :wacko:

#4 donizeth

donizeth

    Normal

  • Usuários
  • 77 posts
  • Sexo:Masculino

Posted 29/10/2008, 10:41

não sei se vai adiantar, ngm anima a ler todo esse codigo teu, mais vai uma dica, ja tentou usar o LIKE do SQL?

$sql_busca = mysql_query("SELECT * FROM tabela WHERE nome LIKE '$campo%' ");

ou

$sql_busca = mysql_query("SELECT * FROM tabela WHERE nome LIKE '%$campo' ");

ou

$sql_busca = mysql_query("SELECT * FROM tabela WHERE nome LIKE '%$campo%' ");

posta ae...




0 user(s) are reading this topic

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

IPB Skin By Virteq