如何在 PHP 的自动完成文本框中显示 2 个不同的字段


how to show 2 different fields in autocomplete textbox in php?

我正在使用此功能在自动完成中显示字段,并且它对我有用。

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;
}

但是我需要在自动完成文本框中显示不同的值。 它向我显示学校名称,但我也需要显示学校国家。例如,如果用户键入i,则其显示indragandhi学校。但我希望它应该归还印度和英德拉甘地学校。

将代码替换为以下代码。我假设您的国家/地区字段是"国家/地区"。如果不是,请将 [国家] 替换为您的国家/地区字段名称。

  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;
    }