Ver Mensaje Individual
  #4 (permalink)  
Antiguo 28/01/2012, 10:48
Seisler
 
Fecha de Ingreso: febrero-2011
Mensajes: 83
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: Validar un nombre de la base de datos al instante

He estado mirando la pagina que has dicho, pero me ha quedado una duda, ellos lo que hacen es comprobar si existe el nombre de una lista predefinida con este php:

Código PHP:
Ver original
  1. <?php
  2.  // Fill up array with names
  3.  $a[]="Anna";
  4.  $a[]="Brittany";
  5.  $a[]="Cinderella";
  6.  $a[]="Diana";
  7.  $a[]="Eva";
  8.  $a[]="Fiona";
  9.  $a[]="Gunda";
  10.  $a[]="Hege";
  11.  $a[]="Inga";
  12.  $a[]="Johanna";
  13.  $a[]="Kitty";
  14.  $a[]="Linda";
  15.  $a[]="Nina";
  16.  $a[]="Ophelia";
  17.  $a[]="Petunia";
  18.  $a[]="Amanda";
  19.  $a[]="Raquel";
  20.  $a[]="Cindy";
  21.  $a[]="Doris";
  22.  $a[]="Eve";
  23.  $a[]="Evita";
  24.  $a[]="Sunniva";
  25.  $a[]="Tove";
  26.  $a[]="Unni";
  27.  $a[]="Violet";
  28.  $a[]="Liza";
  29.  $a[]="Elizabeth";
  30.  $a[]="Ellen";
  31.  $a[]="Wenche";
  32.  $a[]="Vicky";
  33.  
  34.  //get the q parameter from URL
  35.  $q=$_GET["q"];
  36.  
  37.  //lookup all hints from array if length of q>0
  38.  if (strlen($q) > 0)
  39.    {
  40.    $hint="";
  41.    for($i=0; $i<count($a); $i++)
  42.      {
  43.      if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
  44.        {
  45.        if ($hint=="")
  46.          {
  47.          $hint=$a[$i];
  48.          }
  49.        else
  50.          {
  51.          $hint=$hint." , ".$a[$i];
  52.          }
  53.        }
  54.      }
  55.    }
  56.  
  57.  // Set output to "no suggestion" if no hint were found
  58.  // or to the correct values
  59.  if ($hint == "")
  60.    {
  61.    $response="no suggestion";
  62.    }
  63.  else
  64.    {
  65.    $response=$hint;
  66.    }
  67.  
  68.  //output the response
  69.  echo $response;
  70.  ?>

Pero yo quiero comprobarlo de una base de datos, que debería hacer? poner una consulta sql con un bucle que termine cuando llegue al final de la lista? no se muy bien como empezar.

Un saludo.