Ver Mensaje Individual
  #4 (permalink)  
Antiguo 03/11/2009, 09:02
Avatar de kaninox
kaninox
 
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 7 meses
Puntos: 49
Respuesta: datos dentro de un array

no me funciona el temita o bien es el sueño que no me deja pensar, les dejo mi codigo completo para que vean que necesito hacer....

Código php:
Ver original
  1. <?php
  2. include ("include.php"); // conectamos a la base de datos
  3.  
  4.     $aUsers = array(
  5.     "Alejandro",
  6.         "Gonzalo",
  7.     "Marcos",
  8.     "Pedro"
  9.     );
  10.     $input = strtolower( $_GET['input'] );
  11.     $len = strlen($input);
  12.     $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0;
  13.    
  14.    
  15.     $aResults = array();
  16.     $count = 0;
  17.    
  18.     if ($len)
  19.     {
  20.         for ($i=0;$i<count($aUsers);$i++)
  21.         {
  22.             // had to use utf_decode, here
  23.             // not necessary if the results are coming from mysql
  24.             //
  25.             if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
  26.             {
  27.                 $count++;
  28.                 $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
  29.             }
  30.            
  31.             if ($limit && $count==$limit)
  32.                 break;
  33.         }
  34.     }  
  35.     header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  36.     header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
  37.     header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  38.     header ("Pragma: no-cache"); // HTTP/1.0
  39.  
  40.     if (isset($_REQUEST['json']))
  41.     {
  42.         header("Content-Type: application/json");
  43.    
  44.         echo "{\"results\": [";
  45.         $arr = array();
  46.         for ($i=0;$i<count($aResults);$i++)
  47.         {
  48.             $arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
  49.         }
  50.         echo implode(", ", $arr);
  51.         echo "]}";
  52.     }
  53.     else
  54.     {
  55.         header("Content-Type: text/xml");
  56.  
  57.         echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
  58.         for ($i=0;$i<count($aResults);$i++)
  59.         {
  60.         echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
  61.         }
  62.         echo "</results>";
  63.     }
  64. ?>

entonces la idea es generar ese array(); con una consulta :/
este es el link del script que estoy usando a lo mejor y sirve para orientarse...

http://www.brandspankingnew.net/spec...ocomplete.html
__________________
Gokuh Salvo al mundo. PUNTO!!!!