Jquery UI自动完成MySQL/PHP

Fre*_*sen 2 php mysql jquery jquery-ui

我有这个PHP代码:

// connect to mysql
require_once('includes/connect.php');
// include config
include('includes/config.php');

$nameser = $_GET['term'];

$search = Array();
$names = '';
$result = mysql_query("SELECT name FROM customers WHERE name LIKE '%".$nameser."%'");
while ($row = mysql_fetch_assoc($result))
    $names = json_encode($row['name']);

echo $names;
Run Code Online (Sandbox Code Playgroud)

但输出格式不正确,因此自动完成脚本无法弄清楚它应该用它做什么.

此外,此示例仅输出1个条目,但应该远远超过此条目.

有任何想法吗?

flo*_*ree 5

这是正确的代码:

$names = array();
while ($row = mysql_fetch_assoc($result))
  $names[] = $row['name'];

echo json_encode($names);
Run Code Online (Sandbox Code Playgroud)

并且由于mysql_*函数已弃用,请考虑使用mysqliPDO.