如何使用PHP和Angular JS过滤mySQL中的记录


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

我有一些记录存储在mysql数据库。我想检索记录使用php,然后显示基于用户过滤器,如价格范围,类型等…

这应该在用户点击过滤条件时发生(不会有任何提交按钮来应用过滤器)。

您可以分三个步骤开发它:

  1. 设置-点击'过滤器'点击
  2. 发送php请求并检索记录
  3. 在此之后更新作用域变量,并确保在attributes
  4. 中配置了过滤器

这里是:

实时预览

<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;
    };
}]);

希望我帮到你。