March 19, 2017
Display data from MySQL Database Using AngularJS with PHP

Hi friends, In this post we going to see how to display data from Mysql database using AngularJS with PHP. I will share very helpful things with you. Nowadays AngularJS is the best choice to develop the web application. If you are going to begin a new project, then why not choose AngularJS as front-end and PHP as back-end. So in this post, I will show you how to display data from MySQL using AngularJS and PHP.
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>softAOX | Display data from Mysql Database Using AngularJS with PHP</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> </head> <body> <div class="container"> <h3 align="center">Display data from Mysql Database Using AngularJS with PHP</h3> <div ng-app="sa_display" ng-controller="controller" ng-init="display_data()"> <table class="table table-bordered"> <tr> <th>S.No</th> <th>Name</th> <th>Email</th> <th>Age</th> </tr> <tr ng-repeat="x in names"> <td>{{x.id}}</td> <td>{{x.name}}</td> <td>{{x.email}}</td> <td>{{x.age}}</td> </tr> </table> </div> </div> <!-- Script --> <script> var app = angular.module("sa_display", []); app.controller("controller", function($scope, $http) { $scope.display_data = function() { $http.get("display.php") .success(function(data) { $scope.names = data; }); } }); </script> </body> </html> |
display.php
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php $conn = mysqli_connect("localhost", "root", "", "angularjs"); $output = array(); $query = "SELECT * FROM insert_emp_info"; $result = mysqli_query($conn, $query); if(mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_array($result)) { $output[] = $row; } echo json_encode($output); } ?> |
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]