How to create Basic Pagination in PHP/MSQLI

Pagination is generally implied “a procedure for separating printing or digital content into discrete pages”.’ Pagination in PHP’ helps you to maintain your data especially when you will find huge info in the data source and need to display them on the web webpage. So it is not a good encounter to display the entire record on a single long page.

What Doest Pagination Means:

Identifies and refers to numbering web pages in a record.
Refers/Identifies separating a document into pages. Many word processors instantly auto paginate documents depending on a page size that you designate. Some word processors allow you to avoid widows and orphans during pagination.

What Is The Use Of Pagination:

Sometimes you will find huge info in the data source and need to display them on the web webpage. So it is not a good encounter to display the entire record on a single long page.

so we need to organize that data upon more than one web pages to make all of them more user friendly and easy to comprehend by using an approach called paging or pagination, this technique mainly use intended for online document to break over the whole article in different internet pages to remove difficulty and get them to easy to understand.

How you can Create pagination in Php?

Inside the article, I’m likely to implement pagination to organize record on multiple pages to create them readable and more users friendly.

pagination php mysql

pagination in PHP is the interesting suggestions in web development, we can produce pagination in PHP applying ajax, jquery nicely however in this short training, we produced pagination simply using core PHP and MySQL.

The creation of pagination(pagination in PHP) is a very convenient task in Php you are able to create these pages just make use of the following actions.

1 . You have to make a database simply visit the localhost/phpmyadmin and create a data source and then build a table in this database and insert a few record inside the table. as with this tutorial I a new database “student” consist of 1 table which usually contains college student record.

2. Save you’ve created a fresh file within a text publisher like notepad++ or other whatever you using and save the file in c travel like c: //xampp/htdocs/filename.php. then simply copy the next code and past inside the newly produced file and modify all of them according to your need.

3. Create hyperlink and add inside the bottom from the table.

php ide
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
//database connection
$con=mysqli_connect(“localhost”,“root”,“”,“student”);
 //number of record per page
 $per_page=5;
$page=$_REQUEST[‘p’];
$page=$page1;
$p=$page*$per_page;
$query=“SELECT * from record limit “.$p.“,”.$per_page;
$run=mysqli_query($con,$query);
//create a table to in simple html to display record
echo “<table width=\”40{259aa7b25b5fbd0fcc7d226e5713a2bd97ee9334ffe4aa47aad008442822b150}\”  border=2>”;
echo “<tr><td width=\”40{259aa7b25b5fbd0fcc7d226e5713a2bd97ee9334ffe4aa47aad008442822b150}\” align=center bgcolor=’yellow’>ID</td>
 
<td width=\”40{259aa7b25b5fbd0fcc7d226e5713a2bd97ee9334ffe4aa47aad008442822b150}\” align=center bgcolor=’yellow’>Name</td>
<td width=\”40{259aa7b25b5fbd0fcc7d226e5713a2bd97ee9334ffe4aa47aad008442822b150}\” align=center bgcolor=’yellow’>fname</td>
<td width=\”40{259aa7b25b5fbd0fcc7d226e5713a2bd97ee9334ffe4aa47aad008442822b150}\” align=center bgcolor=’yellow’>marks</td></tr>”;
//fetch data from database
while ($row=mysqli_fetch_array($run)) {
        $id=$row[‘s_id’];
        $name=$row[‘s_name’];
        $fname=$row[‘f_name’];
        $marks=$row[‘marks’];
//display the data in table
echo “<tr><td align=center>$id</td>
 
<td  align=’center’ > $name</td>
<td  align=’center’>$fname</td>
<td align=’center’>$marks</td></tr>”;
}
echo“</table>”;
//fetch total record from database
$select_query=mysqli_query($con,“SELECT * FROM record”);
$count=mysqli_num_rows($select_query);
$check=$page*$per_page;
//previous button
if($_REQUEST[‘p’]>1)
{
$prev_page=$_REQUEST[‘p’]1;
echo ‘<a  href=”index.php?p=’.$prev_page.‘”>prev</a>’;
}
//
$limit=$count/$per_page;
$limit=ceil($limit);
for ($i=1; $i <=$limit ; $i++) {
if($i==$_REQUEST[‘p’])
{
      echo “<strong>.$i.</strong>”;
    }
    else{
    echo “<a href=’index.php?p=’.$i.”>.$i.</a>”;
}
}
//next button
if($count>$check)
{
$next_page=$_REQUEST[‘p’]+1;
echo ‘<a  href=”index.php?p=’.$next_page.‘”>next</a>’;
}
?>

the outcome of the over code is usually:

In the above pagination in PHP tutorial, I have used very basic Php and MySQL function and queries if you guess the code you will find it very easy to understand and easy to use. You can change the code according to your requirement and you can use it all kind of web development project.

Sending
User Review
0 (0 votes)