Ver Mensaje Individual
  #4 (permalink)  
Antiguo 13/07/2010, 17:05
Avatar de Master_raven
Master_raven
 
Fecha de Ingreso: junio-2008
Ubicación: Guatemala City, Guatemala, Guatemala
Mensajes: 95
Antigüedad: 15 años, 10 meses
Puntos: 3
Respuesta: Busqueda Instantanea

Buscando encontre este, esta muy chulo asi que decidi entrarle :)

Código HTML:
Ver original
  1. <script type="text/javascript" src="js/bsn.AutoSuggest_2.1.3.js" charset="utf-8"></script>
  2. <link rel="stylesheet" href="css/autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />
  3.  
  4.  
  5. <h3>Ejemplo de autobusqueda</h3>
  6.  
  7. <div><input type="hidden" id="testid" />
  8.     Person : <input type="text" id="testinput_xml" value="" style="width:300px" />
  9.  
  10. </div>
  11.  
  12.  
  13. <script type="text/javascript">
  14.     var options = {
  15.         script:"test.php?json=true&limit=6&",
  16.         varname:"input",
  17.         json:true,
  18.         shownoresults:false,
  19.         maxresults:6,
  20.         callback: function (obj) { document.getElementById('testid').value = obj.id; }
  21.     };
  22.     var as_json = new bsn.AutoSuggest('testinput', options);
  23.    
  24.    
  25.     var options_xml = {
  26.         script: function (input) { return "test.php?input="+input+"&testid="+document.getElementById('testid').value; },
  27.         varname:"input"
  28.     };
  29.     var as_xml = new bsn.AutoSuggest('testinput_xml', options_xml);

y el php esta asi
Código PHP:
Ver original
  1. <?php
  2.     $aUsers = array(
  3.         "Ädams, Egbert",
  4.         "Altman, Alisha",
  5.         "Archibald, Janna",
  6.         "Auman, Cody",
  7.         "Bagley, Sheree",
  8.         "Ballou, Wilmot",
  9.         "Bard, Cassian",
  10.         "Bash, Latanya",
  11.         "Beail, May",
  12.         "Black, Lux",
  13.         "Bloise, India"
  14.     );
  15.    
  16.     $aInfo = array(
  17.         "Bedfordshire",
  18.         "Buckinghamshire",
  19.         "Cambridgeshire",
  20.         "Cheshire",
  21.         "Cornwall",
  22.         "Cumbria",
  23.         "Derbyshire",
  24.         "Devon",
  25.         "Dorset",
  26.         "Durham"
  27.     );
  28.    
  29.    
  30.     $input = strtolower( $_GET['input'] );
  31.     $len = strlen($input);
  32.     $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0;
  33.    
  34.    
  35.     $aResults = array();
  36.     $count = 0;
  37.    
  38.     if ($len) {
  39.         for ($i=0;$i<count($aUsers);$i++) {
  40.             if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)          {
  41.                 $count++;
  42.                 $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
  43.             }
  44.            
  45.             if ($limit && $count==$limit)
  46.                 break;
  47.         }
  48.     }
  49.    
  50.    
  51.    
  52.    
  53.    
  54.     header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  55.     header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
  56.     header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  57.     header ("Pragma: no-cache"); // HTTP/1.0
  58.    
  59.    
  60.    
  61.     if (isset($_REQUEST['json'])) {
  62.  
  63.     } else {
  64.         header("Content-Type: text/xml");
  65.  
  66.         echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
  67.         for ($i=0;$i<count($aResults);$i++)
  68.         {
  69.             echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
  70.         }
  71.         echo "</results>";
  72.     }
  73. ?>

que tengo que editar para sustituir esos array por una busqueda en mi bace de datos
__________________
<?APRENDIENDO