Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá galera
Tenho um codigo em php e js, no qual a maneira que for digitando ele vai mostrando os resultados do BD, estes resultados tem que ser links para postar o codigo em um outra pagina, mas mostra o resultado e quando clico ele mostra o ultimo valor da lista, onde devia mostra o codigo que cliquei...
tai os codigos:
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Teste</title>
<link rel="stylesheet" type="text/css" href="css/admin.css" />
<script src="script.js"></script>
<script>
function pesquisa(valor)url="busca_produto.php?valor="+valor;
ajax(url);
}
</script>
</head>
</html>
<html>
<head>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="35" height="12"> </td>
<td width="708"> </td>
</tr>
<tr>
<td height="21"> </td>
<td valign="top"><font size="2" face="verdana" class="style1">Inicio</font></td>
</tr>
<tr>
<td> </td>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="35">
<form action="resultado.php" method="post" enctype="multipart/form-data" name="form" id="form">
<table width="100%" border="0" bgcolor="#f7f7f7">
<tr>
<td>Codigo:
<input type="text" name="codigo" onKeyUp="pesquisa(this.value)" autocomplete="off" value="<? $codigo = $_POST['codigo'];?>"></td>
</tr>
<tr>
<td>
<div id="pagina"></div></td>
</tr>
</table>
</form> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
busca_produto.php
<?php
if(!empty($_GET["valor"]))
{
$conexao=mysql_connect("localhost","root","");
mysql_select_db("seducao");
$sql="select * from produtos where codigo like '$_GET[valor]%' ORDER BY codigo";
$resultado=mysql_query($sql) or die (mysql_error());
$linhas=mysql_num_rows($resultado);
if($linhas>0){
while($pegar=mysql_fetch_array($resultado))
echo "<input name='codigo' type='hidden' id='codigo' size='30' value='$pegar[codigo]'>
<a href='javascript: void(0);' onClick='javascript:document.form.submit();' title='Confirmar'><div class='confirm'>$pegar[codigo] - $pegar[nome]</div></a>";
}
}
?>
resultado.php
<?
$cod = $_POST['codigo'];
echo $cod;
?>
Agradeço se puder me ajudar...
Carregando comentários...