简体   繁体   中英

How to filter records form mySQL using PHP and Angular JS?

I have some records stored in mysql db. I want to retrieve the records using php and then display based on the users filters like price range, type etc...

This should happen as soon as user click on the filtering criteria (there will not be any submit button to apply the filter).

Your inputs will be very much appreciated.

You can develop it in 3 steps:

  1. set up ng-click on 'filter' click
  2. send an request for php and retrieve records
  3. update scope variable after that and be sure you configured filter in attributes

here is:

live preview

HTML

<div ng-app="myApp">
  <div ng-controller="example">
      <table>
          <thead>
              <th ng-click="customOrder('value')">
                  <a href="#">digits</a>
              </th>
              <th ng-click="customOrder('text')">
                  <a href="#">owners</a>
              </th>
          </thead>
          <tr ng-repeat="value in a_response | orderBy:orderMe">
              <td>{{value.value}}</td>
              <td>{{value.text}}</td>
          </tr>
      </table>
  </div>
</div>

JS

var myApp = angular.module('myApp', []);
myApp.controller('example', ['$scope', function($scope) {
    $scope.a_response = [{
        value: 2,
        text: 'Ivan'
    }, {
        value: 3,
        text: 'Jack'
    },{
        value: 'text',
        text: 'Stack'
    }, {
        value: 1,
        text: 'Lack'
    }];
    $scope.orderMe = 'value';
    $scope.customOrder = function(ordering) {
        //TODO php request and a_resposne updating
        $scope.orderMe = ordering;
    };
}]);

hope i helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM