Jump to content
JFernandesVR

Problema com pesquisa em php

Recommended Posts

JFernandesVR

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

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

<?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();

?>

Edited by yoda

Share this post


Link to post
Share on other sites
brunoais

Demasiada confusão. Preciso de mais pormenores incluindo o HTMLe o js que é enviado para o browser.

Edited by brunoais

"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.