I am using this function to show fields in autocomplete and its working for me.
function finderschool_autocomplete($string) {
$result = db_query("SELECT
* FROM {node} WHERE title LIKE '%$string%' AND type='school' LIMIT 10");
$matches = array();
foreach($result as $item) {
$display = $item->node_title."[school]";
$matches[$item->nid] = $display;
}
drupal_json_output($matches);
exit;
}
But I need to show different values in autocomplete textbox. its showing me school name but I need to show school country as well. For example if user type i then its show indragandhi school.. But I want it should return india and indragandhi school.
Replace your code with following code. I am assuming that your country field is "country". IF not please replace [country] with your country field name.
function finderschool_autocomplete($string) {
$result = db_query("SELECT
* FROM {node} WHERE title LIKE '%$string%' AND type='school' LIMIT 10");
$matches = array();
foreach($result as $item) {
$display = $item->node_title."[school]"." - "."[country]";
$matches[$item->nid] = $display;
}
drupal_json_output($matches);
exit;
}