2017-05-11 14 views
0

我想要使用PHP和AngularJS來更新$codeNum;但它只更新最後的ng-repeat值,而不是點擊的值。使用PHP和angularJS進行簡單更新

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'; 
    } 
} 
+0

你想要哪個x obj? –

+0

顯示你的名字。 –

+0

謝謝你的工作,我只是有一些其他的錯誤。謝謝 – SalamSalam

回答

1

傳遞你x對象作爲參數去更新功能..

<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; 
       }); 
     } 
+0

我做到了,仍然有同樣的問題,只有最後一個值得到更新 – SalamSalam

+0

我想更新ng-repeat的點擊值的代碼,因爲我有一個列表每個代碼與一個按鈕 – SalamSalam

+0

其中x obj你想要嗎? –

相關問題