Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching Data From MYSQL Server using AngularJS

Tags:

html

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>
like image 448
Thakur Yogeshwar Singh Avatar asked Nov 26 '25 04:11

Thakur Yogeshwar Singh


1 Answers

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;});
like image 119
bencrinkle Avatar answered Nov 28 '25 18:11

bencrinkle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!