简体   繁体   English

从表 php Angularjs 中删除选定的行

[英]delete selected rows from table php Angularjs

i'm trying to delete multiple rows from table using angularjs and php, the problem i'm facing that i'm only able to delete one row each time !我正在尝试使用 angularjs 和 php 从表中删除多行,我面临的问题是我每次只能删除一行!

this is my table:这是我的桌子:

<div class="table-responsive" style="overflow-x: unset;">           
    <button class="btn btn-danger" ng-click="deleteBulk()" >Delete</button>
    <table datatable="ng" dt-options="vm.dtOptions" class="table table-bordered table-striped" >
        <thead>
            <tr>                
                <th ><input type="checkbox" ng-model="master" > select</th>
                <th>date</th>
                <th>first name</th>
                <th>last name</th>
                <th>age</th>
                <th>action</th>
                <th>action</th>
                <th>action</th>
            </tr>
        </thead>
        <tbody>
            <tr id="<?php echo $row["id"]; ?>" ng-repeat="name in namesData">
                <td name="checkbox">
                  <input type="checkbox" name="arrExample"
                         ng-model="arrInput" ng-true-value="{{name.id}}"
                         ng-checked="master"
                         ng-click='pushInArray(name.id)'>
                </td>
                <td>{{name.date}}</td>
                <td>{{name.first_name}}</td>
                <td>{{name.last_name}}</td>
                <td>{{name.age}}</td>
                <td><button type="button" ng-click="fetchSingleData(name.id)"
                            class="btn btn-warning btn-xs">edit</button></td>
                <td><button type="button" ng-click="deleteData(name.id)"
                            class="btn btn-danger btn-xs">delete</button></td>
                <td><button type="button" ng-click="single_move(name.id)"
                            class="btn btn-success btn-xs">send</button></td>            
            </tr>
        </tbody>            
    </table>

and this is my Angular code:这是我的 Angular 代码:

$scope.exampleArray = [];
$scope.pushInArray = function(id) {
     // get the input value
     var inputVal = id;
     var array = $scope.exampleArray.push(inputVal);
     $scope.deleteBulk = function(){
        if(confirm("Are you sure you want to delete this record?")){
             $http({
                 method:"POST",
                 url:"insert.php",
                 data:{'id':id, 'action' : 'deleteBulk'}
             }).success(function(data){
                    $scope.success = true;
                    $scope.error = false;
                    $scope.successMessage = data.message;
                    $scope.fetchData();
             });
        }
    };   
};

and this is my php code inside insert.php这是我在 insert.php 中的 php 代码

if($form_data->action == "deleteBulk")
{
    $query = "
     DELETE FROM orders WHERE id='".$form_data->id."'
    ";
    $statement = $connect->prepare($query);
    if($statement->execute())
    {
        $output['message'] = 'done!';
    }
}

can anyone tell me how to fix it please?谁能告诉我如何解决它?

thank you谢谢你

Don't define a scope function inside another scope function:不要在另一个 scope ZC1C425268E68385411AB5074C1A7 中定义 scope function

ERRONEOUS错误

$scope.exampleArray = []; $scope.pushInArray = function(id) { // get the input value var inputVal = id; var array = $scope.exampleArray.push(inputVal); $scope.deleteBulk = function(){ if(confirm("Are you sure you want to delete this record?")){ $http({ method:"POST", url:"insert.php", data:{'id':id, 'action': 'deleteBulk'} }).success(function(data){ $scope.success = true; $scope.error = false; $scope.successMessage = data.message; $scope.fetchData(); }); } }; };

BETTER更好的

$scope.exampleArray = [];
$scope.pushInArray = function(id) {
    // get the input value
    var inputVal = id;
    $scope.exampleArray.push(inputVal);
};

$scope.deleteBulk = function(){
    if(confirm("Are you sure you want to delete this record?")){
         $http({
             method:"POST",
             url:"insert.php",
             data:{'id':id, 'action' : 'deleteBulk'}
         }).then(function(response){
             var data = response.data;   
             $scope.success = true;
             $scope.error = false;
             $scope.successMessage = data.message;
             $scope.fetchData();
         });
    }
};   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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