Foros del Web » Programando para Internet » PHP »

Autocompletar

Estas en el tema de Autocompletar en el foro de PHP en Foros del Web. Buenos dias, tengo este autocompletar que he pillado de internet y quisiera ponerle una recuperación de la base de datos con un select. Como podría ...
  #1 (permalink)  
Antiguo 26/10/2012, 01:54
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Autocompletar

Buenos dias, tengo este autocompletar que he pillado de internet y quisiera ponerle una recuperación de la base de datos con un select.
Como podría hacerlo?

Código PHP:
<?php

/*
note:
this is just a static test version using a hard-coded countries array.
normally you would be populating the array out of a database

the returned xml has the following structure
<results>
    <rs>foo</rs>
    <rs>bar</rs>
</results>
*/

    
$aUsers = array(
        
        
"Zaun, Jillie"
    
);
    
    
    
$aInfo = array(
        
"Bedfordshire"
        
    
);
    
    
    
$input strtolower$_GET['input'] );
    
$len strlen($input);
    
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0;
    
    
    
$aResults = array();
    
$count 0;
    
    if (
$len)
    {
        for (
$i=0;$i<count($aUsers);$i++)
        {
            
// had to use utf_decode, here
            // not necessary if the results are coming from mysql
            //
            
if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
            {
                
$count++;
                
$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
            }
            
            if (
$limit && $count==$limit)
                break;
        }
    }
    
    
    
    
    
    
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    
header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); // always modified
    
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    
header ("Pragma: no-cache"); // HTTP/1.0
    
    
    
    
if (isset($_REQUEST['json']))
    {
        
header("Content-Type: application/json");
    
        echo 
"{\"results\": [";
        
$arr = array();
        for (
$i=0;$i<count($aResults);$i++)
        {
            
$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
        }
        echo 
implode(", "$arr);
        echo 
"]}";
    }
    else
    {
        
header("Content-Type: text/xml");

        echo 
"<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
        for (
$i=0;$i<count($aResults);$i++)
        {
            echo 
"<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
        }
        echo 
"</results>";
    }
?>
Gracias y un saludo
  #2 (permalink)  
Antiguo 27/10/2012, 03:27
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Autocompletar

Para el que lo necesite:

http://discussion.oslund.ca/2011/01/...uggest-plugin/

Gracias

Etiquetas: html, mysql, autocompletado
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:14.