angularjs串連資料庫尋找刪除操作

來源:互聯網
上載者:User

標籤:oct   back   sel   fetch   div   roo   getattr   第一個   query   

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>

<body>
<div ng-app="myApp" ng-controller="myctrl">
<table width=‘100%‘ border="1" cellspacing="0">
<tr>
<th>姓名</th>
<th>性別</th>
<th>年齡</th>
<th>操作</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="刪除" uid={{x.userid}} ng-click="del($event)"><input type="button" value="修改" uid={{x.userid}}></td>  //uid是自己定的屬性 並賦值    del(傳自己為對象進去) 相當於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("資料請求失敗");
});


$scope.del=function(event){
var id=event.target.getAttribute("uid");//擷取當前對象的uid值

$http({
method:‘GET‘,
params :{ id : id},//第一個id是後台php接受的參數名稱  第二個id是本頁面擷取的刪除的id值
url:"php/angu_test_del.php"
}).then(function successCallback(response){
window.location.reload();
},function errorCallback(response){
alert("刪除失敗");
});
}
})
</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串連資料庫尋找刪除操作

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.