【问题标题】:How to filter records form mySQL using PHP and Angular JS?如何使用 PHP 和 Angularjs 从 mySQL 中过滤记录?
【发布时间】:2023-03-13 20:36:02
【问题描述】:

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

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

我们将非常感谢您的意见。

【问题讨论】:

  • 搜索有关PDOSQL的内容

标签: javascript php mysql angularjs


【解决方案1】:

您可以通过 3 个步骤进行开发:

  1. 设置 ng-click on 'filter' click
  2. 发送php请求并检索记录
  3. 之后更新范围变量并确保在属性中配置过滤器

这里是:

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

希望我能帮上忙。

【讨论】:

  • 感谢伊利亚的回复。如果可能的话,请你用伪代码详细说明一下。
  • 这个 codepen 可能会让你满意,在这里:a link 点击标题和过滤器会起作用
  • 感谢它真的有帮助。我应该调用我的 php 代码来填充 $scope.a_response 吗?(目前是它的静态 json)
  • 您可以使用 $http 服务从 Angular 向您的服务器调用 ajax get 请求,服务器应该返回一些 json,这会更改 $scope.a_response。我已经用 $http 请求更新了 codepen。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-22
  • 2016-11-08
相关资源
最近更新 更多