[development] Active select(?)

Ámon Tamás amont at 5net.hu
Thu Sep 18 08:10:22 UTC 2008


Hello,

I have a table with 10000+ record (id, name). I like to make a field
like autocomplete but I like to get back the id not the name. Now I make 
this:

function autocomplete_athlete($string = '') {
     $matches = array();
     if ($string) {
       $result = db_query_range("SELECT a.item_id, a.name FROM names as 
a WHERE a.name LIKE LOWER('%s%%')", $string, 0, 10);
       while ($user = db_fetch_object($result)) {
         $matches[$user->name. '#'.$user->item_id] = $user->name;
       }
     }
   drupal_json($matches);
}

And on the onblur javascript event I change the field to the id with a 
split. But I think this is not a very nice solution.

How can I make it to nice?

Ámon Tamás
Sitefejlesztő és programozó
-- 
5NET Informatikai Kft.
1062 Budapest, Aradi utca 38. A 3/11
telefon: (1) 461-0205  |  fax: (1) 461-0206
e-mail: amont at 5net.hu  |  web: http://www.5net.hu



More information about the development mailing list