โค้ด: เลือกทั้งหมด
<div ng-app="AutocompleteApp" ng-controller="AutocompleteCtrl">
<dl style="clear: left;" id="panel_tag">
<div class="rh_tag_cat">
<input type="text" ng-model="keywords" ng-change="search()">
</div>
<div>
<p ng-show="loading">Loading...</p>
<p ng-hide="loading">Response: [[response]]</p>
<p ng-hide="loading">writed: [[keywords]]</p>
</div>
</dl>
</div>
โค้ด: เลือกทั้งหมด
var app = angular.module('AutocompleteApp', []);
app.config(function ($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
})
app.service('searchService', ['$http', function ($http) {
return {
search: function (keywords) {
return $http.post('{URL_JSON_SHOW_SEARCH}', {"keywords_search": keywords});
}
}
}]);
app.controller('AutocompleteCtrl', ['$scope', 'searchService', function ($scope, searchService) {
$scope.search = function () {
searchService.search($scope.keywords).then(function (response) {
console.log($scope.response);
$scope.response = response.data;
});
};
}]);
ไฟล์ php
โค้ด: เลือกทั้งหมด
public function search() {
$data = file_get_contents("php://input");
$objData = json_decode($data);
$sql = 'SELECT * FROM ' . $this->m_tag_category . " WHERE tag_name LIKE '%".$objData->keywords_search."%' ORDER BY tag_name ASC ";
$query = $this->db->sql_query($sql);
$data = array();
while ($row = $this->db->sql_fetchrow($query)) {
$data[$row['id']]['name'] = $row['tag_name'];
$data[$row['id']]['count'] = $row['count'];
$data[$row['id']]['confederation'] = 0;
$data[$row['id']]['rank'] = $row['count'];
$data[$row['id']]['id'] = $row['id'];
}
$json_response = new \phpbb\json_response;
$json_response->send(array($data));
}