Simple Pagination Using PHP MySQL - ASP TANMOY

Latest

Thursday 17 March 2016

Simple Pagination Using PHP MySQL

Welcome to our Profile.
www.shrilekha.com
How may I help you ?




Create an E-commerce Website ans sell your products online.
contact or whats app: 9999451554 or visit www.99websites.in



Prmote your Website on Famous Search Engine.
Hire us for Best SEO of Your Website.
Contact or Whats app: 9999451554
or visit www.99websites.in



If your Webpage with more number of record and you are showing limited record and all other record you wants to show page wise. When you will click on next page your then your next record will show.The solution is to create a paging system on your page. Follow the code you will Understand the paging in webpage. I have created this application in PHP with MYSQL.


............................................
HTML and PHP Code

<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>


.............................................
Add CSS it will looks better

..............................................
Add CSS
#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;
}




..............................................



No comments:

Post a Comment