3

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

下面是我的代码:

 <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> 

建议患者.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);
 ?>

但它没有得到预输入效果。你能帮我弄清楚我的代码中缺少什么吗?非常感谢您的帮助。

4

1 回答 1

0

如果您阅读文档,它会声明source应该是数组或 javascript 函数。

于 2013-07-15T15:58:49.440 回答