autocomplete - doesn't search in full string

autocomplete - doesn't search in full string

hello. im using this php to generate source for my autocomplete:

  1. $return_arr = array();
  2. $get_item = mysql_query("SELECT * FROM my_table WHERE name LIKE '%" . $_GET['term'] . "%' ORDER BY id");
  3. while($item = mysql_fetch_assoc($get_item)) {
  4.     $row_array['id'] = $item['id'];
  5.     $row_array['label'] = $item['name'].' - '.$item['city'];
  6.     $row_array['value'] = $item['name'].' - '.$item['city'];
  7.     $row_array['city'] = $item['city'];
  8.     array_push($return_arr,$row_array);
  9. }
  10. echo json_encode($return_arr);
  1. $('#inputfield').autocomplete({
  2.         source: "ajax_data.php",
  3.         minLength: 2
  4.     });
now i have for example same five values in db in column 'name' (value: "myname") and 5 different values in column 'city' ("prague", "ny", "madrid", "london", "washington")

so when i enter "myname" into my input field autocomplete offers:
  • myname - prague
  • myname - ny
  • myname - madrid
  • myname - london
  • myname - washington
but when i add the dash so the input text is "myname - ", input doesn't offer anything (doesn't work even with just one space: "myname ")

where's the problem?
thanks