为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用Angularjs在mysql中获取特定id的数据

如何使用Angularjs在mysql中获取特定id的数据

PHP
慕哥6287543 2021-06-16 17:15:55
我有一个基于 PHP angularjs 的 Web 界面,当他们使用 angular 登录时,我应该获取特定用户的数据进行编辑我所能做的就是 ng-repeat 获取所有 id 的所有行控制器.js文件var crudApp = angular.module('crudApp',[]);crudApp.controller("DbController",['$scope','$http', function($scope,$http){  // Function to get employee details from the database  getInfo();  function getInfo(){    // Sending request to EmpDetails.php files    $http.post('databaseFiles/Details.php').success(function(data){      // Stored the returned data into scope      $scope.details = data;    });  }index.php 文件<tr ng-repeat="detail in details| filter:search_query">    <td>{{$index + 1}}</td>    <td>{{detail.trainer_name}}</td>    <td>{{detail.trainer_team}}</td>    <td>{{detail.trainer_code}}</td>    <td>        <button class="btn btn-warning" ng-click="editInfo(detail)" title="Edit">             <span class="glyphicon glyphicon-edit"></span>        </button>    </td>    <td>        <button class="btn btn-danger"                 ng-click="deleteInfo(detail)" title="Delete">            <span class="glyphicon glyphicon-trash"></span>        </button>    </td></tr>详情.php<?php// Including database connectionsrequire_once 'database_connections.php';// mysqli query to fetch all data from database$query = "SELECT * from pokedstats";$result = mysqli_query($con, $query);$arr = array();if(mysqli_num_rows($result) != 0) {while($row = mysqli_fetch_assoc($result)) {$arr[] = $row;}}// Return json array containing data from the databaseconecho $json_info = json_encode($arr);?>我只想显示与特定 id 相关的行,但我只能获取所有行值并显示它们并对其进行编辑。我只希望具有唯一 ID 的特定用户只能编辑行数据或将其删除。
查看完整描述

1 回答

?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

if在您的editInfo和deleteInfo方法中使用语句来检查用户的权限。这是一些伪代码,可以为您提供想法:


$scope.permissionLevelRequired = 3;

$scope.userPermission = 1; // Get this from the database instead


$scope.editInfo(detail) {

  if ($scope.userPermission >= $scope.permissionLevelRequired) {

    // Make changes to `detail`

    ...

  }

}


$scope.deleteInfo(detail) {

  if ($scope.userPermission >= $scope.permissionLevelRequired) {

    // Make changes to `detail`

    ...

  }

}

这只是客户端验证,它适用于您的界面目的,但很容易被黑客入侵。在更改数据库之前,您可能还想验证服务器上的权限。


查看完整回答
反对 回复 2021-06-25
  • 1 回答
  • 0 关注
  • 89 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信