2014-11-21 166 views
0

我有一個包含填充信息的組合框(由mysql_query填充)我想添加自動完成。PHP中的自動完成組合框

$urun_bul=""; 

$sorgug = mysql_query("SELECT x FROM y order by z asc"); 

while($yyy = mysql_fetch_array($sorgug)) 

{ 

$urun_bul.='<option value="'.$yyy["urun_id"].'">'.$yyy["urun_kodu"].' - '.$yyy["urun_adi"].'</option>'; 

} 

然後打印$ urun_bul

+1

你的問題在哪裏? – 2014-11-21 10:17:03

+0

你有一個組合框,你想自動完成?它沒有任何意義。 – Pupil 2014-11-21 10:19:37

+0

嘗試http://jqueryui.com/autocomplete/ – Pupil 2014-11-21 10:20:07

回答

1

只是嘗試 click here

你會使用這個例子您的選項標籤綁定MySQL的

OR

例:

index.php文件

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title></title> 
    <link rel="stylesheet" href="chosen.css"> 
    <style type="text/css" media="all"> 
    /* fix rtl for demo */ 
    .chosen-rtl .chosen-drop { left: -9000px; } 
    </style> 
</head> 
<body> 
    <form> 
    <div id="container"> 
     <div id="content"> 

     <div class="side-by-side clearfix"> 
     <?php mysql_connect("hostname","username","password"); mysql_select_db("database_name"); ?> 

     <div> 
      <em>Select option with DB using autocomplete</em> 
      <select data-placeholder="Choose a Country..." class="chosen-select" style="width:350px;" tabindex="2"> 
      <option value=""></option> 
      <?php $sorgug = mysql_query("SELECT x FROM y order by z asc"); 
       while($yyy = mysql_fetch_array($sorgug)){ 
      ?> 
       <option value="<?php echo $yyy["urun_id"]; ?>"><?php echo $yyy["urun_kodu"].' - '.$yyy["urun_adi"]; ?></option> 
      <?php } ?> 
      </select> 
     </div> 
     </div> 

    </div> 
    </div> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> 
    <script src="chosen.jquery.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
    var config = { 
     '.chosen-select'   : {}, 
     '.chosen-select-deselect' : {allow_single_deselect:true}, 
     '.chosen-select-no-single' : {disable_search_threshold:10}, 
     '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'}, 
     '.chosen-select-width'  : {width:"95%"} 
    } 
    for (var selector in config) { 
     $(selector).chosen(config[selector]); 
    } 
    </script> 
    </form> 

</body> 
</html> 

請從下載的代碼從上面的鏈接和過去的複製chosen.csschosen.jquery.js文件到您的文件夾在您的index.php文件是定位。

+0

正是這樣,在Standart Select – 2014-11-21 10:37:47

+0

我將如何綁定它? – 2014-11-21 10:46:49

+1

首先從這裏下載演示[鏈接](https://github.com/harvesthq/chosen/releases)下載點擊** chosen_v1.2.0.zip ** 然後刪除你不需要的代碼 – 2014-11-21 11:00:39