How to filter autocomplete results in text boxes

后端 未结 1 1800
我寻月下人不归
我寻月下人不归 2021-01-16 23:18

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 organ

1条回答
  •  鱼传尺愫
    2021-01-17 00:05

    For organization name

    $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'],
       );
      }
    

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

    jQuery("#searcho").autocomplete({
                      source:'',
                          minLength:1
    select: function (event, ui) {
        var address = ui.item.address;
        jQuery("#addresso").val(address);
      }
    });
    

    Ref -- Jquery autocomplete on select event

    0 讨论(0)
提交回复
热议问题