我想要使用PHP和AngularJS來更新$code
的Num
;但它只更新最後的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';
}
}
你想要哪個x obj? –
顯示你的名字。 –
謝謝你的工作,我只是有一些其他的錯誤。謝謝 – SalamSalam