<! DOCTYPE html>
<meta charset= "Utf-8" >
<body>
<div ng-app= "myApp" ng-controller= "Myctrl" >
<table width= ' 100% ' border= "1" cellspacing= "0" >
<tr>
<th> name </th>
<th> Sex </th>
<th> Age </th>
<th> Operations </th>
</tr>
<TR ng-repeat= "x in List" >
<TD ng-bind= "X.username" ></td>
<TD ng-bind= "X.userage" ></td>
<TD ng-bind= "X.usersex" ></td>
<td><input type= "button" value= "Delete" Uid={{x.userid}} ng-click= "Del ($event)" ><input type= "button" Value= "Modify" uid={{x.userid}}></td>//uid is a property of its own and assigns a value del (to pass itself into the object) equivalent to JS this
</tr>
</table>
</div>
</body>
<script src= "Js/angular.min.js" charset= "Utf-8" ></script>
<script type= "Text/javascript" >
var app=angular.module (' myApp ', []);
App.controller (' Myctrl ', function ($scope, $http) {
$http ({
Method: ' GET ',
URL: "php/angu_test_sel.php"
}). Then (function Successcallback (response) {
$scope. list=response.data.msg;
},function Errorcallback (response) {
Alert ("Data request Failed");
});
$scope. Del=function (event) {
var id=event.target.getattribute ("UID");//Gets the UID value of the current object
$http ({
Method: ' GET ',
Params: {id:id},//first ID is background php accepts parameter names the second ID is the deleted ID value obtained from this page
URL: "php/angu_test_del.php"
}). Then (function Successcallback (response) {
Window.location.reload ();
},function Errorcallback (response) {
Alert ("Delete failed");
});
}
})
</script>
<?php
Header (' content-type:text/html; Charset=utf8 ');
$conn =mysql_connect ("localhost", "root", "root");
mysql_query ("Use txt");
if ($conn) {
if ($_get) {
$uid =$_get["id"];
$sql = "Delete from test1 where userid= $uid";
$res =mysql_query ($sql);
if ($res >0) {
Echo ' {' status ': ' 1 '} ';
}else{
Echo ' {' status ': ' 0 '} ';
}
}
}else{
Echo ' {' status ': '-2 '} ';
}
?>
<?php
Header (' content-type:text/html; Charset=utf8 ');
$conn =mysql_connect ("localhost", "root", "root");
mysql_query ("Use txt");
if ($conn) {
$sql = "SELECT * from Test1";
$res =mysql_query ($sql);
if (mysql_num_rows ($res) >0) {
while ($row =mysql_fetch_assoc ($res)) {
$arr []= $row;
}
Echo ' {' status ': ' 1 ', ' msg ': '. Json_encode ($arr). '} ';
}
}else{
Echo ' {' status ': '-2 '; MSG ":" Fail to connect "}";
}
?>
ANGULARJS Connection Database Lookup delete operation