使用PHP和angularJS进行简单更新 [英] simple update with PHP and angularJS

查看:109
本文介绍了使用PHP和angularJS进行简单更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PHP和AngularJS更新 Num $ code ;但它只更新最后的 ng-repeat 值,而不是更新的值。

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:

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


推荐答案

通行证你的 x 对象作为更新函数的参数..

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

这篇关于使用PHP和angularJS进行简单更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆