drddx3115 2019-05-05 05:19
浏览 179

如何从数据库自动完成bootstrap php mysql ajax

autocomplete not working i want fetch data from mysql database like google option my file not working not showing any thing when we key down select data from sugested option

please sugest some good code my code is not running it is not working now sir and auto select is not showing similar answer this is link where showing but not selecting any data under key selection this is link where show nothing

     <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <!--my file not working auto complete address from database-->
    <!--code inclide file of botstarp -->
<script        
   src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script>  
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
        <!--code of auto fetch-->
      <script>
     $(document).ready(function () {
       $('#Country').typeahead({
        source: function (query, result) {
            $.ajax({
                url:"autoselect_jquery5.php",
                data:'query=' + query,            
                dataType:"json",
                type:"POST",
                success: function (data) {
                    result($.map(data, function (item) {
                        return item;
                    }));
                }
            });
           }
        });
     });
      </script>
       </head>


       <body>
       div class="container" style="width:600px;">
      <h2 align="center">Autocomplete Textbox using Bootstrap Typeahead with Ajax PHP</h2>

                 <label>Search Country</label>
       <input type="text"name="country"id="country"autocomplete="off"placeholder="Country" />
     </div>
 </body>
   <   /html> 

       <!--second file which fetching data from from database -->
     // autoselect_jquery5.php file for fetch code
       <?php
     include 'database.php';

     if (isset($_POST['query'])) {
     $search_query = $_POST['query'];


      $query = "SELECT * FROM transporter WHERE address LIKE 
  '%".$search_query."%' LIMIT 12";
   $result = mysqli_query($link, $query);
  $data = array();

    if(mysqli_num_rows($result) > 0)
   {
    while($row = mysqli_fetch_assoc($result))
     {
        $data[] = $row["address"];
     }
      echo json_encode($data);
          }
      }
       ?>




    }
  • 写回答

2条回答 默认 最新

  • donglisi8644 2019-05-05 06:14
    关注

    for autocomplete, you can use typehead.js its works with the bootstrap check below ex.

    How do we set remote in Typeahead.js?

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?