Baljeet Singh

1 minute read

In this tutorial, i will be explaining how to fetch data from the mysql database via angularjs via GET ajax call. I will be using angularjs $http service to get data from the mysql database with php. Note: create a mysql database, with students table having two fields Name(varchar), Roll(int). Also insert some values. Copy the following contents to their respective file & you are done.


<!DOCTYPE html>
<html ng-app="fetch">
<title>AngularJS GET request with PHP</title>
  <link rel="stylesheet" href="//">
        <script src=""></script>

  <div class="row">
    <div class="container">
      <h1>Angular $http GET Ajax Call</h1>
      <div ng-controller="dbCtrl">
      <input type="text" ng-model="searchFilter" class="form-control">
		<table class="table table-hover">
					<th>Roll No</th>
				<tr ng-repeat="students in data | filter:searchFilter">

	var fetch = angular.module('fetch', []);

	fetch.controller('dbCtrl', ['$scope', '$http', function ($scope, $http) {
				$ = data;
			.error(function() {
				$ = "error in fetching data";



//database settings
$connect = mysqli_connect("hostname", "username", "password", "dbname");

$result = mysqli_query($connect, "select * from students");

$data = array();

while ($row = mysqli_fetch_array($result)) {
  $data[] = $row;
    print json_encode($data);
comments powered by Disqus