【问题标题】:simple update with PHP and angularJS使用 PHP 和 angularJS 进行简单更新
【发布时间】:2017-10-10 07:13:06
【问题描述】:

我想使用 PHP 和 AngularJS 更新 $codeNum;但它只更新最后一个 ng-repeat 值,而不是点击的那个。

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

更新.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';  
  }  
}

【问题讨论】:

  • 你想要哪个 x obj?
  • 显示你的名字。
  • 谢谢它的工作,我只是有一些其他的错误。谢谢

标签: php angularjs ionic-framework


【解决方案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; 
              });  
       } 

【讨论】:

  • 我做到了,但仍然有同样的问题,只有最后一个值得到更新
  • 我只想更新 ng-repeat 的点击值的代码,因为我有一个带有按钮的每个代码的列表
  • 你想要哪个 x obj?
  • 你想在哪里给 ng-repeat 里面的按钮
  • 它是相同的 x ,这只是因为当我只放一个 ng-repeat 时,我没有得到所有的值。我想有一个每个值为 ng-repeat 的按钮,这就是为什么我把按钮放在列表中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-29
  • 2014-01-27
  • 1970-01-01
  • 2014-04-16
  • 1970-01-01
相关资源
最近更新 更多