simple update with PHP and angularJS

2020-05-09 03:37发布

I want to update Num of $code, using PHP and AngularJS; but it updates only the last ng-repeat value, and not the clicked one.

HTML:

<ion-content class="padding" ng-controller="AdminCtrl" ng-repeat="x in names| filter: {Num: thisX}:true">

      <ion-list ng-repeat="x in names| filter: {Num: thisX}:true">
              <ion-item> 
              <div class="item item-divider center-text" ng-model='x.Code'> {{x.Code}} </div>
      <ion-item>
      <b>Date</b> <span class="item-note">  {{x.Date}} </span>
      </ion-item>
             <a class="button button-info" ng-click="update()">Update</a>
            ...

app.js:

$scope.update = function(){ 

     $http.post("http://localhost/deb/update.php",
      {
        'Code' :$scope.x.Code,                 
      }
      ).success(function(data){
        alert(data);  
        $scope.thisX = $state.params.Num; 
      });  
} 

update.php:

$data = json_decode(file_get_contents("php://input"));  

if (count($data) > 0)  
{   
  $Code = mysqli_real_escape_string($connect, $data->Code);                 
  $query = "UPDATE sale
    SET 
    Num=Null WHERE Code='$Code'"; 
  if(mysqli_query($connect, $query))  
  {  
    echo "modification réussie ...";  
  }  
  else  
  {  
       echo 'Error';  
  }  
}

1条回答
Lonely孤独者°
2楼-- · 2020-05-09 04:08

Pass your x object as param to update function..

<a class="button button-info" ng-click="update(x)">Update</a>

 $scope.update = function(x){ 

             $http.post("http://localhost/deb/update.php",
              {
                'Code' :x.Code,                 
              }
              ).success(function(data){
                alert(data);  
             $scope.thisX = $state.params.Num; 
              });  
       } 
查看更多
登录 后发表回答