Create pagination with php functions

If you don’t know about pagination and how to create it then here is a tutorial for pagination in php with the help of functions. Pagination is very important if we are creating dynamic sites and there are lots of ways to creating it. Creating pagination is tricky way, Firstly you should know about the structure that how it will work; like how many result you want to show, I have used very simple way so that anybody can understand whether he is beginner or he is very good programmer.

In this I have used bootstrap; If you don’t have knowledge of bootstrap then you can learn bootstrap here. This script is not depends on bootstrap but I have used bootstrap for writing this article in easy way. You can apply this script on your running project but I suggest you to test this script separately so that you can learn very well and then you may apply. So if you want to learn then just follow the following simple steps.

In this article I have created a database “users” and table “users” where I stored the data of many users (Demo Data).

1.    First of all create database “Users”.
2.    Create table “users”.
3.    In this table create 3 field id, name and email.

Now your database is configured.

Create Functionality for pagination

1.    Create “pagination” folder on your localhost (Wamp or Xampp).
2.    Create “index.php” file in this folder and paste the code below.

        Php Pagination with functions
'; // print_r($data); // echo ''; for($d=0;$d
Name Email
3.    Now create a “function.php” and paste the code below.
	// Database connectivity
	mysql_connect("localhost","root","") or die(mysql_error());
	mysql_select_db("users") or die(mysql_error());

	// Creating function for fetching data from database.
	function fetch_data($start,$limit){
		$countRows=mysql_query("SELECT * FROM users");
		$fetchAllData="SELECT * FROM users LIMIT $start,$limit";
			$res['name'][]=	$data['name'];
		return $res;
4.    I have also create a “style.css” file and the code is below.
	margin-top: 30px;

#mainContainer ul{
	text-align: center;



Web Hosting