Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/10/2012, 11:29
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Recuperar datos de autocompletar en campos de texto independientes

Hola, tengo un autocompletar que me funciona bien pero los datos recuperados se me imprimen todos en el mismo campo que es:
Código HTML:
Ver original
  1. <input type="text" size="100" value="" name="apellidos" id="apellidos" autocomplete="off"  />
y lo que quiero es recuperarlos en input independientes.

Este es parte de el formulario:

Código PHP:
<div id="wrapper">
       <
form action="index_ajax.php" method="get">
           <
div class="ausu-suggest">
              <
input type="text" size="30" value="" name="telefono" id="telefono" autocomplete="off" />
              <
input type="text" size="100" value="" name="apellidos" id="apellidos" autocomplete="off"  />
              <
input type="text" size="100" value="" name="poblacion" id="poblacion" autocomplete="off"  />
               <
input type="text" size="100" value="" name="aparato" id="aparato" autocomplete="off"  />
          </
div>
       </
form

y este el php

Código PHP:
<?php
/*
 * AUSU jQuery-Ajax Autosuggest v1.0
 * Demo of a simple server-side request handler
 * Note: This is a very cumbersome code and should only be used as an example
 */

# Establish DB Connection
$con    =   mysql_connect("localhost","root","root");
if (!
$con){ die('Could not connect: ' mysql_error()); }
mysql_select_db("pruebas"$con);

# Assign local variables
$id     =   @$_POST['id'];          // The id of the input that submitted the request.
$data   =   @$_POST['data']; 

if (
$id && $data)
{
    if (
$id=='telefono')
    {
        
$query "SELECT U.nombre, U.apellidos, U.num_usuario, U.telefono, D.poblacion, au.num_aparato, au.aparato, au.modelo, au.marca, au.num_serie
, au.num_producto, au.fecha_compra
FROM usuarios U

INNER JOIN dir_usuarios D ON U.num_usuario = D.num_usuario

INNER JOIN ap_usuarios au ON U.num_usuario = au.num_usuario

WHERE CONCAT( nombre, ' ', apellidos ) LIKE '%$vnm%' AND U.telefono LIKE '%$data%' AND D.poblacion LIKE '%$vpo%' GROUP BY U.num_usuario
                  "
;
     
$result mysql_query($query);

        
$dataList = array();

        while (
$row mysql_fetch_array($result))
        {
        
$toReturn   $row['telefono'];
        
$dataList[] = '<li id="' .$row['apellidos'] .$row['poblacion'].$row['aparato']. '"><a href="#">' htmlentities($toReturn) . '</a></li>';
                      
            
        }
     if (
count($dataList)>=1)
        {
            
$dataOutput join("\r\n"$dataList);
            echo 
$dataOutput;
        }
        else
        {
            echo 
'<li><a href="#">No Results</a></li>';
        }
}
}
?>
Gracias.