Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

Problema com pesquisa em php

$
0
0
Criei um formulário de pesquisa.
Porém quando tento pesquisar alguma coisa, ele faz a pesquisa direitinha e chega a um certo ponto está sempre a adicionar o mesmo produto e a página nao para de atualizar.
aqui vai o código da função

Código (PHP):
<?php
function pesquisaartigos($texto)

{ $tipo = "";
$SID = SID;
$sql = "SELECT * FROM artigos WHERE Referencia LIKE '%" . $texto . "%'";
                         $rs=$this->bd->executarSQL($sql);
$n=0;
$id=1;

echo ("<tr><td colspan=\"4\"><div align=\"center\" class=\"style2\">Resultados da pesquisa por: " . $texto . " na referencia do artigo.</div></td></tr>");

                         while(mysql_fetch_row($rs)) {
         $num = $n +1;
         $id = mysql_result($rs, $n, "Referencia");
         $marca = mysql_result($rs, $n, "Marca");
         if (mysql_result($rs, $n, "Imagem") == ""){


         echo ("<tr><td height=\"40\" width=\"80\" ><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b><img src=\"images/semimagempq.jpg\" width=\"80\" height=\"60\" border=0/></a>");
         echo "<br></td>";
       
         }else {
                                 echo ("<tr><td height=\"40\" width=\"80\"> <b><a href=Artigo.php?". $SID . "&id=" . $id . "></b><img src=\"images/" .mysql_result($rs, $n, "Imagem") . "\" width=\"80\" height=\"60\" border=0/></a>");
         echo "<br></td>";
}
                                 echo ("<td height=\"40\" width=\"10%\" valign=\"middle\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b>".mysql_result($rs, $n, "Referencia")."</a></span></div>");
         echo "<br></td>";
                                 echo ("<td height=\"40\" width=\"50%\" valign=\"middle\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b>".mysql_result($rs, $n, "DescricaoPT")."</a></span></div>");
         echo "<br></td>";
       
         if(isset($_SESSION['login_status'])){
       
         $tipo = ($_SESSION['tipo']);
         if ($tipo == 'Empresa'){
       
         echo ("<td height=\"40\" width=\"15%\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b> € ".mysql_result($rs, $n, "PrecoEMP")."</a></span></div>");
         echo "<br></td>";
         }else if ($tipo == 'Revenda'){
         echo ("<td height=\"40\" width=\"15%\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b> € ".mysql_result($rs, $n, "PrecoREV")."</a></span></div>");
         echo "<br></td>";
} else{
         echo ("<td height=\"40\" width=\"15%\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b> € ".mysql_result($rs, $n, "PrecoPVP")."</a></span></div>");
         echo "<br></td>";
         } }else {
         echo ("<td height=\"40\" width=\"15%\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b> € ".mysql_result($rs, $n, "PrecoPVP")."</a></span></div>");
         echo "<br></td>";
         }
if (mysql_result($rs, $n, "Marca") == ""){
echo ("<td height=\"40\" ><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b><img src=\"images/semimagempq.jpg\" width=\"80\" height=\"60\" border=0/></a>");
         echo "<br></td>";
         }else{
                                 echo ("<td height=\"40\" width=\"60\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><b><a href=marca.php?". $SID . "&id=" . $marca . "></b><img src=\"images/marcas/" . mysql_result($rs, $n, "Marca"). ".jpg\" width=\"80\" height=\"60\" border=0/></a></span></div>");
         echo "<br></td></tr>";
                       
$n++;
}}

         $sql2 = "SELECT * FROM artigos WHERE DescricaoPT LIKE '%" . $texto . "%'";
                         $rs2=$this->bd->executarSQL($sql2);
$n2=0;
$id2=1;
echo ("<tr><td colspan=\"4\"><div align=\"center\" class=\"style2\">Resultados da pesquisa por: " . $texto . " no nome do artigo.</div></td></tr>");   
         while(mysql_fetch_row($rs2)) {


         $num2 = $n2 +1;
         $id2 = mysql_result($rs2, $n2, "Referencia");
         $marca2 = mysql_result($rs2, $n2, "Marca");
                       
         if (mysql_result($rs2, $n2, "Imagem") == ""){

         echo ("<tr><td height=\"40\" width=\"80\" ><b><a href=Artigo.php?". $SID . "&id=" . $id2 . "></b><img src=\"images/semimagempq.jpg\" width=\"80\" height=\"60\" border=0/></a>");
         echo "<br></td>";
       
         }else {
                                 echo ("<tr><td height=\"40\" width=\"80\"> <b><a href=Artigo.php?". $SID . "&id=" . $id2 . "></b><img src=\"images/" .mysql_result($rs2, $n2, "Imagem") . "\" width=\"80\" height=\"60\" border=0/></a>");
         echo "<br></td>";
}
                                 echo ("<td height=\"40\" width=\"10%\" valign=\"middle\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id2. "></b>".mysql_result($rs2, $n2, "Referencia")."</a></span></div>");
         echo "<br></td>";
                                 echo ("<td height=\"40\" width=\"50%\" valign=\"middle\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id2. "></b>".mysql_result($rs2, $n2, "DescricaoPT")."</a></span></div>");
         echo "<br></td>";
       
         if(isset($_SESSION['login_status']))
         {
         $tipo = ($_SESSION['tipo']);
         if ($tipo == 'Empresa'){
       
         echo ("<td height=\"40\" width=\"15%\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b> € ".mysql_result($rs2, $n2, "PrecoEMP")."</a></span></div>");
         echo "<br></td>";
         }else if ($tipo == 'Revenda'){
         echo ("<td height=\"40\" width=\"15%\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b> € ".mysql_result($rs2, $n2, "PrecoREV")."</a></span></div>");
         echo "<br></td>";
} else{
         echo ("<td height=\"40\" width=\"15%\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b> € ".mysql_result($rs2, $n2, "PrecoPVP")."</a></span></div>");
         echo "<br></td>";
         } }else {
         echo ("<td height=\"40\" width=\"15%\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><br><b><a href=Artigo.php?". $SID . "&id=" . $id . "></b> € ".mysql_result($rs2, $n2, "PrecoPVP")."</a></span></div>");
         echo "<br></td>";
         }
if (mysql_result($rs2, $n2, "Marca") == ""){
echo ("<td height=\"40\" ><b><a href=Artigo.php?". $SID . "&id=" . $id2 . "></b><img src=\"images/semimagempq.jpg\" width=\"80\" height=\"60\" border=0/></a>");
         echo "<br></td>";
         }else{
                                 echo ("<td height=\"40\" width=\"60\"><div align=\"left\" class=\"style29\"><span class=\"style20\"><b><a href=marca.php?". $SID . "&id=" . $marca2. "></b><img src=\"images/marcas/" . mysql_result($rs2, $n2, "Marca"). ".jpg\" width=\"80\" height=\"60\" border=0/></a></span></div>");
         echo "<br></td></tr>";
$n2++;
         exit();
}}
}

?>


aqui vai o codigo da pagina pesquisar.php

Código (PHP):
<?php $texto = $_POST['texto'];
echo $texto;?>
         </strong></p>
         <table width="568" height="60" border="0">
         <?php
         $id = "teste";
if (isset ($_REQUEST["id"]))
                 $id = $_REQUEST["id"];
$Campo = $id;
$texto = $_POST['texto'];
// echo $texto;
$pesquisa = new Classe();
// $familia->listarCFamilias($Campo);
$pesquisa->pesquisaartigos($texto);
$pesquisa->endClasse();
               
?>

Viewing all articles
Browse latest Browse all 14700

Trending Articles