mysql - Retrieving data from Database using angular.js and PHP -
i need retrieve data database , bind them in text-field using angular.js , php. explaining code below.
index.php
<?php include_once 'dbconfig.php'; ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>crud operations php , mysql - cleartuts</title> <link rel="stylesheet" href="css/style.css" type="text/css" /> </head> <body> <center> <div id="body"> <div id="content"> <table align="center"> <tr> <th colspan="5"><a href="add_data.html">add data here.</a></th> </tr> <th>first name</th> <th>last name</th> <th>city name</th> <th colspan="2">operations</th> </tr> <?php $sql_query="select * users"; $result_set=mysql_query($sql_query); while($row=mysql_fetch_row($result_set)) { ?> <tr> <td><?php echo $row[1]; ?></td> <td><?php echo $row[2]; ?></td> <td><?php echo $row[3]; ?></td> <td align="center"><a href="edit_data.php?edt_id=<?php echo urlencode($row[0]) ?>"><img src="images/pencil_small.png" align="edit" /></a></td> <td align="center"><a href="javascript:delete_id('<?php echo $row[0]; ?>')"><img src="images/cross-small-icon.png" align="delete" /></a></td> </tr> <?php } ?> </table> </div> </div> </center> </body> </html>
when user click on edit button redirect next page(i.e-edit_data.php
) given below , page contains data going edited.
edit_data.php:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" ng-app="edit_data"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>crud operations php , mysql - cleartuts</title> <link rel="stylesheet" href="css/style.css" type="text/css" /> <script src="js/angularjs.js" type="text/javascript"></script> <script src="js/update.js" type="text/javascript"></script> </head> <body> <center ng-controller="updatecontroller"> <div id="body"> <div id="content"> <table align="center"> <tr> <td><input type="text" name="first_name" placeholder="first name" ng-model="first_name" required /></td> </tr> <tr> <td><input type="text" name="last_name" placeholder="last name" ng-model="last_name" required /></td> </tr> <tr> <td><input type="text" name="city_name" placeholder="city" ng-model="city" required /></td> </tr> <tr> <td> <button type="submit" name="btn-update" ng-click="update_data();"><strong>update</strong></button> </td> </tr> </table> </div> </div> </center> </body> </html>
in page need display fetched data inside text-field.
update.js:
var app=angular.module("edit_data", []); app.controller("updatecontroller",function($scope,$http){ $scope.errors = []; $scope.msgs = []; $scope.update_data=function(){ $http.post('js/update.php',{"first_name":$scope.first_name,"last_name":$scope.last_name,"city":$scope.city} ).success(function(data, status, headers, config){ if(data.msg!=''){ $scope.msgs.push(data.msg); }else{ $scope.errors.push(data.error); } }).error(function(data, status) { // called asynchronously if error occurs // or server returns response error status. $scope.errors.push(status); }); } });
i need retrieve these 3 data first_name,last_name,user_city
mysql database.please me resolve issue.
make php file connect db , retrieve given parameter db, , after call angular :
var app=angular.module("myapp", []); app.controller("updatecontroller",function($scope,$http){ $scope.errors = []; $scope.msgs = []; $scope.update_data=function(){ $http.post('update.php', {"first_name":$scope.first_name,"last_name":$scope.last_name,"city":$scope.ci ty} ).success(function(data, status, headers, config){ $scope.resultdata = data; }).error(function(data, status) { // called asynchronously if error occurs // or server returns response error status. $scope.errors.push(status); }); } });
view file:
<div ng-controller="updatecontroller" ng-app="myapp"> <div ng-repeat=item in resultdata"> {{item.yourdbdata}} </div> </div>
your update php posted data call db , echo json_encode(query result)
Comments
Post a Comment