Simple Pagination Using PHP MySQL

By | January 2, 2014

Webpage with more number of rowed data will make the page lengthier, pagination makes the long rows into small number of rows and remaining in next pages. Pagination in a webpage will make the webpage structure more crispy. Here is the tutorial about how to make simple pagination using php mysql

  

 

 

PHP Code
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<html>
<body>
<div id="content">
<?php
$query1=mysql_connect("localhost","root","");
mysql_select_db("freeze_demo",$query1);

$start=0;
$limit=10;

if(isset($_GET['id']))
{
$id=$_GET['id'];
$start=($id-1)*$limit;
}

$query=mysql_query("select * from pagination LIMIT $start, $limit");
echo "<ul>";
while($query2=mysql_fetch_array($query))
{
echo "<li>".$query2['text1']."</li>";
}
echo "</ul>";
$rows=mysql_num_rows(mysql_query("select * from pagination"));
$total=ceil($rows/$limit);

if($id>1)
{
echo "<a href='?id=".($id-1)."' class='button'>PREVIOUS</a>";
}
if($id!=$total)
{
echo "<a href='?id=".($id+1)."' class='button'>NEXT</a>";
}

echo "<ul class='page'>";
for($i=1;$i<=$total;$i++)
{
if($i==$id) { echo "<li class='current'>".$i."</li>"; }

else { echo "<li><a href='?id=".$i."'>".$i."</a></li>"; }
}
echo "</ul>";
?>
</div>
</body>
</html>

 

 

CSS Code
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
73
74
75
76
77
78
79
80
81
#content
{
width: 900px;
margin: 0 auto;
font-family:Arial, Helvetica, sans-serif;
}
.page
{
float: right;
margin: 0;
padding: 0;
}
.page li
{
list-style: none;
display:inline-block;
}
.page li a, .current
{
display: block;
padding: 5px;
text-decoration: none;
color: #8A8A8A;
}
.current
{
font-weight:bold;
color: #000;
}
.button
{
padding: 5px 15px;
text-decoration: none;
background: #333;
color: #F3F3F3;
font-size: 13PX;
border-radius: 2PX;
margin: 0 4PX;
display: block;
float: left;
}

 

10 thoughts on “Simple Pagination Using PHP MySQL

  1. Angel

    I have lo leave a comment becouse this really help me, the code is too simple and thats whats i like..
    Thanks a lots!
    I am going to click some ads to help u :p

    Reply
  2. Mohammad Zeus

    Hi Dear , I LOVE YOU , AND YOUR WEBSITE !!
    PLEASE KEEP ON WORK :-X

    Reply
  3. Rohir Naik

    Nice Article and i used it too.. But you made one mistake… you should correct it. :)
    You forgot to declare : $paging = 1;

    One can define it just above : if(isset($_GET['id']))

    Eg:
    $paging = 1;
    if(isset($_GET['id'])){

    Reply

Leave a Reply to John Cancel reply

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