php - Speed up query for Autocomplete inputbox -
i'm trying implement autocomplete search box.
i have database table of books, when user starts typing in search box, want able show them suggestion box first 6 titles match words it's beingness typed.
i used ajax query php have next code:
$terms = explode( " ", $data->word ); $terminos = ''; foreach( $terms $term ) { if ( $term == '' || $term == ' ' || strlen($term)==0 ) continue; if ( $terminos != '' ) $terminos .= " , title '%$term%' "; else $terminos .= " title '%$term%' "; } $pdo = mysqlutil::getconnection(); $query = "select title books :terminos limit 6"; $stmt = $pdo->prepare($query); $stmt->bindparam(':terminos', $terminos, pdo::param_str); $stmt->execute(); $result = $stmt->fetchall(pdo::fetch_assoc); if ($result) { homecoming $result; } else { homecoming false; }
this solution slow , need know how speed query.
any ideas?
thanks in advance.
php autocomplete
No comments:
Post a Comment