Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/07/2014, 18:08
Avatar de fedefrankk
fedefrankk
 
Fecha de Ingreso: agosto-2007
Mensajes: 871
Antigüedad: 16 años, 8 meses
Puntos: 7
Pregunta Buscar en tiempo real

Hola a todos, tengo un codigo que busca en tiempo real y anda de 10.
La web funcionaria de la siguiente manera, apenas me meto al index, me mustra las fotos que tienen mas puntos, y a la vez puedo buscar por nombre

por nombre sale, lo que no me sale es al entrar al index no me muestra nada,

no se mucho de ajax (aclaro)

dejo codigo

mi index.html

Código HTML:
Ver original
  1. <script type="text/javascript">
  2.  
  3.      function sugerencias(str){
  4.           var xmlhttp;
  5.           if (str.length==0) {
  6.                document.getElementById("txtHint").innerHTML="";
  7.                return;
  8.           }
  9.           if (window.XMLHttpRequest) {
  10.                xmlhttp=new XMLHttpRequest();
  11.           } else {
  12.                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  13.           }
  14.           xmlhttp.onreadystatechange=function() {
  15.                if ((xmlhttp.readyState==4) && (xmlhttp.status==200)&&(xmlhttp.responseText)) {
  16.                    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  17.                }
  18.           }
  19.           xmlhttp.open("GET","sugerencias.php?q="+str,true);
  20.           xmlhttp.send();
  21.      }
  22.  
  23.          
  24.     </script>
  25.     <h2>Sugerencias</h2>
  26.         <p>Introduce un nombre en la siguiente casilla</p>
  27.         <form action="">
  28.             Primer nombre: <input type="text" id="txt1"  onKeyUp="sugerencias(this.value)">
  29.         </form>
  30.     <div class="galeria" id="txtHint"></div>


mi php

sugerencias.php

Código PHP:
Ver original
  1. <?php
  2.  include("conectar.php");
  3. $cone=conectar();
  4. $innerHTML = "";
  5.  
  6.  if($innerHTML=""){
  7. //Inclusión de la conexión
  8. include("conectar.php");
  9. $cone=conectar();
  10.  
  11.  
  12. $registros=mysqli_query($cone,"select * from img WHERE nombre LIKE '%".$_GET['q']."%' ") or die("Problemas en el select:".mysqli_error());
  13.  
  14. //Sacamos los registros con las divs
  15. while ($reg=mysqli_fetch_array($registros)){
  16.  
  17.      $innerHTML .= '<div class="contenedor_c" id="capa1"><input type="image"  src="../_imgclient/'.$reg['nombre'].'.'.$reg['nombre'].'" width=292 height=211 title="'.$reg['nombre'].'"></div>
  18.     ';
  19.  
  20. }
  21.  
  22. echo $innerHTML;
  23.  
  24.  }else{
  25.     $registros=mysqli_query($cone,"select * from img ORDER BY usu_puntos DESC") or
  26.   die("Problemas en el select:".mysqli_error());
  27. while ($reg=mysqli_fetch_array($registros)){
  28.  
  29.  $innerHTML .= '<div class="contenedor_c" id="capa1"><input type="image"  src="../_imgclient/'.$reg['nombre'].'.'.$reg['nombre'].'" width=292 height=211 title="'.$reg['nombre'].'"></div>';
  30.  
  31. echo $innerHTML;
  32. } }
  33.  
  34.  ?>

Espero que se entienda
saludos a todos
fede