Autocomplete problem
Autocomplete problem
Hello.
I'm trying to create autocomplete using jquery ui with php but it's not working.
I don't know what I'm doing wrong.
index.php
- <p><label>Team host:</label><input type='text' name='team_host' value="" class='auto'></p>
ajax.js
- $(function() {
-
- //autocomplete
- $(".auto").autocomplete({
- source: "search.php",
- minLength: 1
- });
- });
search.php
-
- <?php
require_once 'dao/TeamHostDAO.php';
require_once 'includes/Connection.php';
$teamhostdao = new TeamHostDAO();
$keyword=isset($_GET['team_host']) ?isset($_GET['team_host']):'null';
if($keyword){
$teamHosts = $teamhostdao->selectByKeyword($keyword);
}
function select by keyword in TeamHostDAO
- public function selectByKeyword($keyword){
- $result=array();
- try {
- $sql="SELECT team_host FROM teams_host WHERE team_host LIKE :team_host";
- $stmt= $this->connection->prepare($sql);
- $stmt->bindValue(':team_host','%'.$keyword.'%', PDO::PARAM_STR);
-
- $stmt->execute();
-
-
- while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- //echo $row['email']." ";
- $result[]=$row;
- }
- // return $result;
- } catch (Exception $exc) {
- echo $exc->getTraceAsString();
- echo $exc->getMessage();
- }
- echo json_encode($result);
- }