Fetching Data From MYSQL Server using AngularJS

I have the following code, taken from W3schools,but now I need to fetch the values that are present in a table named, 'create_table' in my 'firstSchema' Database. Kindly help me by suggesting what changes should be made to the code, in order to get it to display the contents on my table.

    <!DOCTYPE html>
<html >
<style>
table, th , td  {
  border: 1px solid grey;
  border-collapse: collapse;
  padding: 5px;
}
table tr:nth-child(odd) {
  background-color: #f1f1f1;
}
table tr:nth-child(even) {
  background-color: #ffffff;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="customersCtrl">

<table>
  <tr ng-repeat="x in names">
    <td>{{ x.Name }}</td>
    <td>{{ x.Country }}</td>
  </tr>
</table>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
   $http.get("http://www.w3schools.com/angular/customers_mysql.php")
   .then(function (response) {$scope.names = response.data.records;});
});
</script>

</body>
</html>

Upvotes: 3

Views: 2684

Answers (1)

bencrinkle
bencrinkle

Reputation: 298

your code seems fine for actually displaying something but obviously you will need to modify your ng-repeat to reflect the data you are getting from your database. I think what you are missing is the server side aspect of the app, you need to replace the call to the w3schools endpoint with your own endpoint and in there you can query your database and return whatever you want.....

$http.get("yourappsomewhere/query_database_in_here.php")
.then(function (response) {$scope.yourdata = response.data;});

Upvotes: 1

Related Questions