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';
}
}
Pass your
x
object as param to update function..