使用jquery和mysql自动完成

时间:2017-07-19 13:34:53

标签: jquery mysql autocomplete

我正在尝试使用以下代码来处理来自mysql数据库表的结果。自动填充建议将来自数据库表。我试图用mysql做一个foreach循环,但它没有用。

做我想做的最简单的方法是什么?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  } );
  </script>
</head>
<body>

<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>


</body>
</html>

我使用以下代码来连接数据库结果。但我不能让它在jquery数组中工作。

require_once("resource/Database.php");
$query ="SELECT username FROM users";
                $select = $db->prepare($query);
                    $select->execute(array());  
            foreach($select as $rs) :   

echo "\"".$rs['username']. "\",<br>"; 

endforeach;
ps:伙计们,如果你认为这个问题是公开的,你必须告诉我原来的问题在哪里。感谢。

0 个答案:

没有答案