来自mysql / JSON的twitter bootstrap typeahead source

时间:2022-07-20 15:53:21

So basically, I want my my typeahead to get source from mysql table.

基本上,我希望我的typeahead从mysql表中获取源代码。

Below is my code:

以下是我的代码:

 <script src="../../js/bootstrap-typeahead.js"></script>
 <script type="text/javascript">
  var patients = [HERE I WANT TO PUT THE SUGGEST_PATIENTS.PHP];
       $('#search_bar').typeahead({source: patients})

 </script> 

suggest_patient.php

suggest_patient.php

 <?php
include('../../db.php');

       $query = $conn->prepare('SELECT * FROM patients WHERE fname LIKE ?');
       $query->execute(array('value%'));

           $output_string = '';

           for($i=0; $row = $query->fetch(); $i++){
                $fname = $row['fname'];
                $lname = $row['lname'];
                $mname = $row['mname'];
                $bday = $row['bday'];
                $religion = $row['religion'];
                $occupation = $row['occupation'];
                $gender = $row['gender'];
                $phoneno = $row['phoneno'];
                $address = $row['address'];
                $type = $row['type'];    
           }

           $output_string = $fname;
      echo json_encode($output_string);
 ?>

But it's not getting the typeahead effect. Can you please help me figure out what's missing in my code? Help is much appreciated.

但它并没有获得先行效应。能否帮我弄清楚我的代码中缺少什么?非常感谢帮助。

1 个解决方案

#1


0  

If you read the documentation it states that the source should be an array or a javascript function.

如果您阅读文档,则说明源应该是数组或javascript函数。

#1


0  

If you read the documentation it states that the source should be an array or a javascript function.

如果您阅读文档,则说明源应该是数组或javascript函数。