JavaScript ProjectsSoftware Projects

How to Create Pagination using AngularJS in PHP

I’ve used CDN for Bootstrap and Angular JS in this tutorial, so you need an internet connection for them to work. This tackles on how to create pagination using angularjs in php.

I’m going to use an external js for pagination which you can view using this link. This is included in the downloadable of this tutorial. I have also created a simple pagination using php and mysql in this link.

Creating A Database

First, we’re going to create our database and insert sample data.

1. Open phpMyAdmin.

2. Click databases, create a database and name it as angular.

3. After creating a database, click the SQL and paste the below codes. See image below for detailed instruction.

CREATE TABLE `members` (
  `memid` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(30) NOT NULL,
  `lastname` varchar(30) NOT NULL,
  `address` text NOT NULL,
PRIMARY KEY(`memid`)
INSERT INTO `members` (`memid`, `firstname`, `lastname`, `address`) VALUES
(1, 'Neovic', 'Devierte', 'Silay City'),
(2, 'Julyn', 'Divinagracia', 'E.B. Magalona'),
(3, 'Gemalyn', 'Cepe', 'Bohol'),
(4, 'Matet', 'Devierte', 'Silay City'),
(5, 'Tintin', 'Devierte', 'Silay City'),
(6, 'Bien', 'Devierte', 'Cebu City'),
(7, 'Cherry', 'Ambayec', 'Cebu City'),
(8, 'Jubilee', 'Limsiaco', 'Silay City'),
(9, 'Janna ', 'Atienza', 'Talisay City'),
(10, 'Desire', 'Osorio', 'Bacolod City'),
(11, 'Debbie', 'Osorio', 'Talisay City'),
(12, 'Nipoy ', 'Polondaya', 'Victorias City'),
(13, 'Johnedel', 'Balino', 'Cauyan, Negros'),
(14, 'Nereca', 'Tajonera', 'Cauayan, Negros'),
(15, 'Jerome', 'Robles', 'Cebu City');


<!DOCTYPE html>
<html lang="en" ng-app="app">
    <meta charset="utf-8">
    <title>AngularJS Pagination with PHP/MySQLi</title>
    <link href="" rel="stylesheet">
    <script src=""></script>
<body ng-controller="memberdata">
<div class="container">
    <h1 class="page-header text-center">AngularJS Pagination with PHP/MySQLi</h1>
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <table class="table table-bordered table-striped" style="margin-top:10px;">
                           <th>Member ID</th>
                    <tr dir-paginate="member in members|itemsPerPage:5">
                        <td>{{ member.memid }}</td>
                        <td>{{ member.firstname }}</td>
                        <td>{{ member.lastname }}</td>
                        <td>{{ member.address }}</td>
            <div class="pull-right" style="margin-top:-30px;">
               boundary-links="true" >
<script src="dirPaginate.js"></script>
<script src="angular.js"></script>


var app = angular.module('app', ['angularUtils.directives.dirPagination']);
app.controller('memberdata',function($scope, $http){
        $scope.members = data; 


    $conn = new mysqli('localhost', 'root', '', 'angular');
    $output = array();
    $sql = "SELECT * FROM members";
        $output[] = $row;
    echo json_encode($output);

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button