如何筛选结果自动完成文本框 [英] How to filter autocomplete results in text boxes

查看:168
本文介绍了如何筛选结果自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建自动完成AJAX搜索一个网站,它自动完成组织的名称和地址seperatly, 但我想它来验证,当有人搜索组织的名称,地址文本应该给汽车只为完整的结果 匹配的搜索组织名称。

I have created autocomplete ajax search for a web site which auto complete organization names and addresses seperatly, but i want it to validate , when someone search organization name, address text should give auto complete results only for matching search organization name.

任何人都可以请咨询我

机构地址AJAX:

$addresso=$_GET["term"];
$query=mysql_query("SELECT * FROM sltdb_cddir_content where fulladdress like '%".$addresso."%' AND categories_id=80  order by fulladdress ASC ");
$json=array();
while($display=mysql_fetch_array($query)){
$json[]=array(
'value'=> $display["fulladdress"],
 'label'=>$display["fulladdress"]
 );
 }

组织名称AJAX

 $searcho=$_GET["term"];
 $query=mysql_query("SELECT * FROM sltdb_cddir_content where title like '%".$searcho."%'AND categories_id=80  ");
 $json=array();
 while($display=mysql_fetch_array($query)){
 $json[]=array(
 'label'=> $display['title'],
 'value' => $display['title'],
  );
  }

自动完成的jQuery的:

autocomplete jquery :

  jQuery.noConflict();
          jQuery(function(){
              jQuery("#addresso").autocomplete({
                  source:'<?php echo JURI::root().'modules/mod_jomdirectory_search/tmpl/gov-address.php'; ?>',

                  minLength:1
              });
          });

          jQuery.noConflict();
          jQuery(function(){
              jQuery("#searcho").autocomplete({
                  source:'<?php echo JURI::root().'modules/mod_jomdirectory_search/tmpl/gov.php'; ?>',

                  minLength:1
              });
          });

形式:

<input id="searchc" class="ui-autocomplete-input" type="text" name="search" "></input>

请注意

我究竟想要的是,当有人请从组织名称文本框中输入值,地址文本框中应加载这关系到organizatoin名自动完成resuls。请指教

what i exactly want is , when someone select a value from organization name text box, address text box should load the auto complete resuls which related to that organizatoin name. please advice

推荐答案

对于组织名称

$searcho=$_GET["term"];
$seachArray = explode(',',$searcho);
$q='';
foreach($seachArray  as $term){
  $q .=" title like '%".trim($searcho)."%'  or ";
}  

$q =substr($q,0 ,-3);
 $query=mysql_query("SELECT * FROM sltdb_cddir_content where ($q) AND categories_id=80  ");
 $json=array();
 while($display=mysql_fetch_array($query)){
   $json[]=array(
    'label'=> $display['title'],
    'value' => $display['title'],
    );
  }

您的评论后,编辑

Edited after your comment

$searcho=$_GET["term"];
 $query=mysql_query("SELECT * FROM sltdb_cddir_content where title like '%".$searcho."%'AND categories_id=80  ");
 $json=array();
 while($display=mysql_fetch_array($query)){
  $json[]=array(
   'label'=> $display['title'],
   'value' => $display['title'],
   'address' =>$display['fulladdress'],
   );
  }

这将包括地址到你的结果。现在你有下面给出您的JS工作。

This will include address into your result. Now you have to work in your js as given below.

jQuery("#searcho").autocomplete({
                  source:'<?php echo JURI::root().'modules/mod_jomdirectory_search/tmpl/gov.php'; ?>',
                      minLength:1
select: function (event, ui) {
    var address = ui.item.address;
    jQuery("#addresso").val(address);
  }
});

参考 - jQuery的自动完成功能上选择事件

这篇关于如何筛选结果自动完成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆