$string . '%')); while ($r = $records->fetchObject()) { $key = "$r->name [id: $r->id]"; $items[$key] = "$r->name"; } drupal_json_output($items); }