elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Ayuda con mi busqueda
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda con mi busqueda  (Leído 2,051 veces)
Rijhording

Desconectado Desconectado

Mensajes: 41


Ver Perfil
Ayuda con mi busqueda
« en: 29 Junio 2010, 10:00 am »

hola compañeros de este foros estoy realizando una busqueda con php dentro de mi misma pagina y resulta que no me busca nada no se que estoy haciendo mal este es mi codigo
TABLA cliente
(
id autoincremet,
apepat varchar(80),
apemat varchar(80),
nombre varchar(80),
fecha date,
dni varchar(8),
direccion varchar(80),
telefono varchar(8),
email varchar(80)
)

id=pk

Código
  1. <?php
  2. include("conexion.php");
  3.  
  4. if($_REQUEST["btnBuscar"]!="" && $_REQUEST["busqueda"]!="")
  5. {
  6.  
  7. if(is_numeric($_REQUEST["busqueda"]))
  8. $filtro="id=". $_REQUEST["busqueda"];
  9. else
  10. $filtro=" apepat like '%".$_REQUEST["busqueda"]."%' or apemat like '%".$_REQUEST["busqueda"]."%' or nombre like '%".        $_REQUEST["busqueda"]."%'";
  11. $mensaje=$filtro;
  12.  
  13. }else
  14. {
  15. $mensaje="<font color='red'>Escriba Algo</font>";
  16. }
  17. $rst_clientes=mysql_query("select * from cliente",$conexion);//ME PARECE QUE ACA DEBO DE PONER UN WHERE PERO NO SE COMO LO DEBO DE PONER PORQUE LO ESTOY FILTRANDO CON EL FILTRO
  18.  
  19. $num_registros=mysql_num_rows($rst_clientes);
  20. if($num_registros==0)
  21. {
  22. echo "No se han encontrado ningun registro aun";
  23. exit();
  24. }
  25. $registros=5;
  26. $pagina=$_GET["num"];
  27. if(is_numeric($pagina))
  28. $inicio=(($pagina-1)*$registros);
  29. else
  30. $inicio=0;
  31. $rst_clientes=mysql_query("select * from cliente order by apepat LIMIT $inicio,$registros",$conexion);//ACA TAMBIEN DEBO DE PONER EL FILTRO QUE E PUESTO ARRIBA PERO NO SE COMO
  32. $paginas=ceil($num_registros/$registros);
  33.  
  34.  
  35. ?>
  36. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  37. <html xmlns="http://www.w3.org/1999/xhtml">
  38. <head>
  39. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  40. <title>::Listar Clientes</title>
  41. <?php
  42. include('links.php');
  43. ?>
  44.  
  45.  
  46.  
  47. <link type="text/css" href="datepicker/jquery.ui.all.css" rel="stylesheet" />
  48. <script type="text/javascript" src="datepicker/jquery-1.4.2.js"></script>
  49. <script type="text/javascript" src="datepicker/jquery.ui.core.js"></script>
  50. <script type="text/javascript" src="datepicker/jquery.ui.widget.js"></script>
  51. <script type="text/javascript" src="datepicker/jquery.ui.datepicker.js"></script>
  52. <link type="text/css" href="demos.css" rel="stylesheet" />
  53.  
  54.  
  55.  
  56. <script type="text/javascript">
  57. $(function() {
  58. $("#datepicker").datepicker();
  59. $("#format").change(function(){ $('#datepicker').datepicker('option', {dateFormat: $(this).val()}); });
  60.  
  61. });
  62. </script>
  63. </head>
  64. <body>
  65. <table width="837" border="0" align="center" id="bgprincipal">
  66.  <tr valign="middle" align="center">
  67.    <td colspan="2"><img src="imagenes/banner.png" width="781" height="123" /></td>
  68.  </tr>
  69.  <tr>
  70.    <?php
  71.   echo "<td colspan=2 align=\"right\" valign=\"middle\">Bienvenido ";
  72. echo  $usuario." | <a href=\"cerrarsesion.php\">Cerrar Sesión</a></td>";
  73. ?>
  74.  </tr>
  75.  <tr>
  76.    <td width="139" height="24"><a href="clientes.php">REGISTRAR</a>-LISTAR</td>
  77.    <td width="688">&nbsp;</td>
  78.  </tr>
  79.  <tr valign="top">
  80.    <td height="150" align="center">
  81. <?php
  82. include('menu.php');
  83.  
  84.  
  85. ?>
  86.  
  87.  
  88.  
  89.  
  90. </td>
  91.    <td align="left" valign="top">
  92. <table width="650" height="10" align="center">
  93. <tr>
  94. <td><div align="right"><a href="clientenuevo.php"><input type="image" src="imagenes/icontexto-user-web20-netvibes.png" title="agregar cliente"/></a></div></td>
  95. </tr>
  96. <tr>
  97.  <td><form id="form1" name="form1" method="get" action="listarclientes.php">
  98.    Buscar
  99.    <input name="busqueda" type="text" id="busqueda" value="<?php echo $_GET["busqueda"];?>" />
  100.        <input  type="image" src="imagenes/magnifier.png"name="btnBuscar" id="btnBuscar" value="Buscar" />
  101.  
  102. <?php
  103.  echo $mensaje;
  104.  
  105.  ?>
  106.  </form>
  107.  
  108.  </td>
  109.  </tr>
  110. </table>
  111.  
  112.  
  113. <table width="650" height="52" border="1" align="center">
  114.  <tr>
  115. <td width="128" bgcolor="#0066FF"><div align="center">Cliente</div></td>
  116.    <td width="58" bgcolor="#0066FF"><div align="center">Fecha</div></td>
  117.    <td width="54" bgcolor="#0066FF"><div align="center">DNI</div></td>
  118.    <td width="83" bgcolor="#0066FF"><div align="center">Direccion</div></td>
  119.    <td width="81" bgcolor="#0066FF"><div align="center">Telefono</div></td>
  120.    <td width="62" bgcolor="#0066FF"><div align="center">Email</div></td>
  121.    <td width="67" bgcolor="#0066FF"><div align="center">Modificar</div></td>
  122.    <td width="58" bgcolor="#0066FF"><div align="center">Eliminar</div></td>
  123.  </tr>
  124.  <?php
  125. while($fila=mysql_fetch_array($rst_clientes))
  126. {
  127. ?>
  128. <tr>
  129. <td><?php echo $fila["apepat"]." ".$fila["apemat"]." ".$fila["nombre"] ;?></td>
  130. <td><?php echo $fila["fecha"] ;?></td>
  131. <td><?php echo $fila["dni"] ;?></td>
  132. <td><?php echo $fila["direccion"] ;?></td>
  133. <td><?php echo $fila["telefono"] ;?></td>
  134. <td><?php echo $fila["email"] ;?></td>
  135. <td align="center"><a href="modificarclientes.php?cod=<?php echo $fila["id"] ;?>"><input type="image" src="imagenes/page_white_edit.png"></a>
  136. <td align="center"><a href="confirmarEliminacion.php?cod=<?php echo $fila["id"] ;?>">
  137. <input type="image"  src="imagenes/cancel.png"></a></tr>
  138. <?php
  139. }
  140.  
  141. ?>
  142. </table>
  143. <p align="center">
  144. <?php
  145. if($pagina>1)
  146. echo "<a href='listarclientes.php?num=".($pagina-1) ."'>Anterior</a> ";
  147.  for($cont=1;$cont<=$paginas;$cont++)
  148.  {
  149.  if($cont==$pagina)
  150.  echo $cont ." ";
  151.  else
  152.   echo "<a href='listarclientes.php?num=". $cont ."'>$cont</a> ";
  153. }
  154. if($pagina<$paginas)
  155. echo "<a href='listarclientes.php?num=".($pagina+1) ."'>Siguiente</a> ";
  156.  
  157.  
  158.  ?>
  159. </p>
  160.  
  161.  
  162.    </td>
  163.  </tr>
  164.  
  165. </table>
  166.  
  167.  
  168.  
  169.  
  170.  
  171. </body>
  172. </html>
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  


En línea

Falso Positivo

Desconectado Desconectado

Mensajes: 243



Ver Perfil WWW
Re: Ayuda con mi busqueda
« Respuesta #1 en: 29 Junio 2010, 12:00 pm »

Hola,

El problema está en las primeras líneas

Código
  1. if($_REQUEST["btnBuscar"]!="" && $_REQUEST["busqueda"]!="")
  2. {
  3.  
  4. if(is_numeric($_REQUEST["busqueda"]))
  5. $filtro="id=". $_REQUEST["busqueda"];
  6. else
  7. $filtro=" apepat like '%".$_REQUEST["busqueda"]."%' or apemat like '%".$_REQUEST["busqueda"]."%' or nombre like '%".        $_REQUEST["busqueda"]."%'";
  8. $mensaje=$filtro;
  9.  
  10. }else
  11. {
  12. $mensaje="<font color='red'>Escriba Algo</font>";
  13. }

Ya que en la variable "$filtro" al parecer armas la consulta para la búsqueda pero en ningún lado la ejecutas ni muestras.

Y luego, ésto es independiente del punto anterior: el funcionamiento de la variable "$mensaje" no me cierra.... o muestra "Escriba Algo" o el contenido de la variable "$filtro" el cual no tiene sentido ya que el echo de "$mensaje" es un texto a mostrar al usuario (auí estaría bien el mostrar"Esriba Algo") pero no así el mostrar lo que toma de $filtro, salvo que te falte una condición para mostrar $mensaje y así meterlo dentro de un tag a.

Saludos.


En línea

Don't worry, be hacked....
Rijhording

Desconectado Desconectado

Mensajes: 41


Ver Perfil
Re: Ayuda con mi busqueda
« Respuesta #2 en: 29 Junio 2010, 16:10 pm »

hola man todo funciona pero no me hace la busqueda en el filtro es para filtrar nada mas lo que quiero esque me haga la busqueda lo contengo en $filtro para hacer la llamada pero noc como lo llamo en select * from cliente where aca debe de estar el $filtro pero noc como lo pongo si supiera como ponerlo ya me estaria haciendo la busqueda correspondiente
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda con la búsqueda de un libro
Foro Libre
fuenteRea 2 1,976 Último mensaje 27 Febrero 2011, 14:43 pm
por Constance
Ayuda con Busqueda dicotomica
Java
maestro kirer 3 4,073 Último mensaje 10 Diciembre 2017, 15:37 pm
por Serapis
ayuda urgente busqueda de texto
Windows
DaVinci4 8 3,622 Último mensaje 10 Julio 2021, 18:14 pm
por Randomize
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines