Angularjs PHP MySQL Pagination Example

By Hardik Savani | May 30, 2019 | | 1828 Viewer | Category : PHP Bootstrap MySql AngularJS

In this tutorial, I want to share with you simple example of php mysql pagination using angularjs. we will use dirPagination.js as Pagination Directive in angularjs paginate using php mysql database.

we will create step by step very basic example of server side pagination in angularjs. pagination is a basic requirement of every project. so here is a simple step of creating pagination with angularjs using php mysql database.

If you looking for crud application with angularjs and php then you can check my already written tutorial: PHP AngularJS CRUD with Search and Pagination Example From Scratch. You can check that also.

Here follow step by step tutorial of angularjs pagination.

Step 1: Create Users Table

First of all we need to use one table as "users". you can create users table using following mysql query. After that you need to add some dummy records on users table.

users table:


`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,

`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,

`email_verified_at` timestamp NULL DEFAULT NULL,

`password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,

`remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,

`created_at` timestamp NULL DEFAULT NULL,

`updated_at` timestamp NULL DEFAULT NULL,

`status` int(11) NOT NULL DEFAULT '0',


) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=203 ;

Step 2: Create Index.php file

In this step we need to create index.php file. In this file we will write angularjs code and write pagination code.

You need to download dirPagination.js file from here: Pagination Directive.

So let's write following code:


<!DOCTYPE html>



<title>Angularjs PHP MySQL Pagination Example -</title>

<link rel="stylesheet" href="" />

<script src=""></script>

<script src="dirPagination.js"></script>



<div class="container" ng-app="myApp" ng-controller="paginateController">

<h3 align="center">Angularjs PHP MySQL Pagination Example -</h3>

<div class="table-responsive">

<table class="table table-striped table-bordered">









<tr dir-paginate="user in users|itemsPerPage:5">

<td>{{ }}</td>

<td>{{ }}</td>

<td>{{ }}</td>





<div align="right">

<dir-pagination-controls max-size="5" direction-links="true" boundary-links="true" >





<script type="text/javascript">

var myPaginateApp = angular.module('myApp', ['angularUtils.directives.dirPagination']);

myPaginateApp.controller('paginateController', function($scope, $http){


$scope.users = data;





Step 3: Create api.php file

Here, we will write code to getting data from database table. so let's create api.php file and write code as bellow:



$hostName = "localhost";

$username = "root";

$password = "root";

$dbname = "58_laravel";

$mysqli = new mysqli($hostName, $username, $password, $dbname);

$sql = "SELECT * FROM users";

$result = $mysqli->query($sql);

while($row = $result->fetch_assoc()){

$data[] = $row;


echo json_encode($data);


Now you can check it.

I hope it can help you....

***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: