Programación php
Email: Password:


¡Regístrate gratis! | ¿Has perdido tu password?

Home
Blog

En él que podrás informarte de todas las noticias relacionadas con el posicionamiento de páginas web.

Ir al Blog de posicionamiento web



Foro de programación en PHP

Responder el mensaje

ayuda con una busqueda utilizando el metodo get

Autor: javamell
Publicado: 11-7-2010 06:12 PM
tengo un formulario con lo siguiente que llama a procesa.phtml:
<!-- Manual de PHP -->
<html>
<head>
<title>Ejemplo de PHP</title>
</head>
<body>
<H1>Ejemplo de procesado de formularios</H1>
Introduzca su telefono:
<FORM ACTION="procesa.phtml" METHOD="GET">
<INPUT TYPE="text" NAME="tele"><BR>
<INPUT TYPE="submit" VALUE="Enviar">
</FORM>
</body>
</html>

Y ESTE ES PROCESA
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
<style type="text/css">
<!--
.Estilo4 {color: #000000; font-family: Arial, Helvetica, sans-serif; }
-->
</style>
</head>

<body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>

<body>
<?php
$tele = "";
include("conex.phtml");
$link=Conectarse();
$result=mysql_query("select * from amigos WHERE telefono like '%$tele%' ",$link);
?>
<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>
<TR bordercolor="#333333"><TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> telefono</span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> nombres </span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> direccion </span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> mail </span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> trabajo </span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> tipo </span></div></TD>
</TR>
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr><td> %s</td><td> %s </td><td> %s</td><td> %s</td><td> %s</td><td> %s</td></tr>",
$row["telefono">,$row["nombre">,$row["direccion">,$row["mail">,$row["trabajo">,$row["tipo">);
}
mysql_free_result($result);
mysql_close($link);
?>
</table>
</body>
</html>

EL PROBLEMA LO TENGO EN EL WHERE NO ME ESTA HACIENDO EL FILTRADO POR EL CAMPO TELEFONO. OTRA COSITA CONO HAGO PARA QUE CUANDO EL TELEFONO NO ES ENCONTRADO ME SAQUE UN MENDAJE.

G R A C I A S
Autor: aquilesnake
Publicado: 15-7-2010 08:27 AM
Limpia tu codigo, esdtas usando dreamwever ?

Pará que lanze un mensaje de no encontrado tiene que hacer un if o siemplemente si no pasa por el proceso manda un echo " "; Al final.

Tu problema debe estár en sinstexis.

revisa bien la conexion y las consulta.
Autor: dcreate
Publicado: 18-7-2010 11:44 AM
Es simple tu problema, lo que pasa es que nunca recuperas la variable cuando la envias, te falta $tele=$_GET['tele']; mira:

[PHP]<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
<style type="text/css">
<!--
.Estilo4 {color: #000000; font-family: Arial, Helvetica, sans-serif; }
-->
</style>
</head>

<body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>

<body>
<?php
$tele = $_GET['tele'];
include("conex.phtml");
$link=Conectarse();
$result=mysql_query("select * from amigos WHERE telefono like '%$tele%' ",$link);
?>
<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>
<TR bordercolor="#333333"><TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> telefono</span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> nombres </span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> direccion </span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> mail </span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> trabajo </span></div></TD>
<TD bgcolor="#FFFFCC"><div align="center"><span class="Estilo4"> tipo </span></div></TD>
</TR>
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr><td> %s</td><td> %s </td><td> %s</td><td> %s</td><td> %s</td><td> %s</td></tr>",
$row["telefono">,$row["nombre">,$row["direccion">,$row["mail">,$row["trabajo">,$row["tipo">);
}
mysql_free_result($result);
mysql_close($link);
?>
</table>
</body>
</html>[/PHP]