我试图为组合框完成自动完成功能,我按照http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/form/forum-search.html做到了
我的 php 查询:
if (!$con) {
throw new Exception("Error in connection to DB");
}
$sql = "SELECT first_name FROM students WHERE first_name ILIKE '%$query%' ORDER BY name ASC";
$result = pg_query($con, $sql);
ORDER BY name ASC";
while ($row = pg_fetch_array($result))
{
$names[] = array('name' => $row[0]);
}
$name_list = array();
$name_list['success'] = true;
$name_list['names'] = $names;
$name_list['totalCount'] = count( $name_list['names'] );
echo json_encode($name_list);
在我的情况下,用户可以输入姓氏而不是学生的名字,因此我需要编辑查询以使其在检查名字的结果为空后检查姓氏。这是我所做但没有工作的:
$sql = "SELECT first_name FROM students WHERE first_name ILIKE '%$query%' ORDER BY name ASC";
$result = pg_query($con, $sql);
if(pg_num_rows($result) == 0)
$sql = "SELECT last_name FROM students WHERE last_name ILIKE '%$query%' ORDER BY name ASC";