Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/08/2014, 21:00
jaaggaaj1
 
Fecha de Ingreso: julio-2014
Mensajes: 12
Antigüedad: 9 años, 9 meses
Puntos: 0
Respuesta: Pequeño problema con buscador

Cita:
Iniciado por Henkka Ver Mensaje
Tu lógica no hace lo que querés hacer: el mensaje de error se presenta cuando el campo está vacío, no cuando no hay resultados.

Claramente debería ser:

Código PHP:
Ver original
  1. if (busqueda no es vacía) {
  2.   // Buscar
  3.   if (resultados > 0) {
  4.     while(hay_resultados)) {
  5.       //resultados
  6.     }
  7.   } else {
  8.     // Mensaje de error, no hubieron resultados
  9.   }
  10. } else {
  11.   //Mensaje de error, el campo está vacío
  12. }

Para obtener la cantidad de resultados de una consulta usa:
Código PHP:
Ver original
  1. mysql_num_rows($busqueda)

Además, recomiendo que uses !== '' en lugar de != "" para comprobar la cadena vacía, ya que PHP trata otros valores como vacíos cuando no los consideraríamos así, como el 0.
"Mi amigo, su ayuda me a venido bastante bien, ya me funciono, se lo agradezco bastante "

Aqui dejo el codigo por si a alguien le surge la misma pregunta que a mi!!

Código PHP:
Ver original
  1. <?php
  2. include "conexion.php";
  3. $busca=$_POST['buscar'];
  4. if ($busca)
  5. {
  6. // Buscar
  7. $busqueda=mysql_query("SELECT * FROM peliculas WHERE nombre LIKE '%".$busca."%'");
  8. if ($f=mysql_num_rows($busqueda) > 0)
  9. {
  10. while($f=mysql_fetch_array($busqueda))
  11. {
  12. //resultados
  13. echo ($f['nombre']."<br>");
  14. echo("<center><a href='index.php'>Regresar al men&uacute; principal</a></center>");
  15. include("fuegos.php");
  16. }
  17. }
  18. else
  19. {
  20. // Mensaje de error, no hubieron resultados
  21. echo("No hay");
  22. echo("Upps!, parece que tu b&uacute;squeda no obtuvo ning&uacute;n resultado, pero no te preocupes,
  23. a&uacute;n puedes perder tu tiempo con los siguientes videos:<br><br>");
  24. echo("<center>");
  25. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/7LKHpM1UeDA' frameborder='0' allowfullscreen></iframe><br><br>");
  26. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/z6cZTkHlCsw' frameborder='0' allowfullscreen></iframe><br><br>");
  27. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/icwoI3uno_c' frameborder='0' allowfullscreen></iframe><br><br>");
  28. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/qTvWpx6dpHk' frameborder='0' allowfullscreen></iframe><br><br>");
  29. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/B1x6KLmczuQ' frameborder='0' allowfullscreen></iframe><br><br>");
  30. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/C8xiy1JZbNk' frameborder='0' allowfullscreen></iframe><br><br>");
  31. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/veEb8rg7SMg' frameborder='0' allowfullscreen></iframe><br><br>");
  32. echo("<a href='index.php'>Regresar al men&uacute; principal</a>");
  33. echo("</center>");
  34. }
  35. }
  36. else
  37. {
  38. //Mensaje de error, el campo está vacío
  39. echo("en blanco");
  40. echo("Upps!, parece que tu b&uacute;squeda no obtuvo ning&uacute;n resultado, pero no te preocupes,
  41. a&uacute;n puedes perder tu tiempo con los siguientes videos:<br><br>");
  42. echo("<center>");
  43. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/7LKHpM1UeDA' frameborder='0' allowfullscreen></iframe><br><br>");
  44. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/z6cZTkHlCsw' frameborder='0' allowfullscreen></iframe><br><br>");
  45. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/icwoI3uno_c' frameborder='0' allowfullscreen></iframe><br><br>");
  46. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/qTvWpx6dpHk' frameborder='0' allowfullscreen></iframe><br><br>");
  47. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/B1x6KLmczuQ' frameborder='0' allowfullscreen></iframe><br><br>");
  48. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/C8xiy1JZbNk' frameborder='0' allowfullscreen></iframe><br><br>");
  49. echo("<iframe width='600' height='400' src='//www.youtube.com/embed/veEb8rg7SMg' frameborder='0' allowfullscreen></iframe><br><br>");
  50. echo("<a href='index.php'>Regresar al men&uacute; principal</a>");
  51. echo("</center>");
  52. }
  53. ?>