Explaination:
In this Tutorial i explained simple Pagination Using PHP.Here not include any javascript and
Jquery library files.Only by using PHP only i done the Pagination with fetching datas from
database.Just here we can get that id and pass that in to pagination href link.
I hope this tutorial is very helpfull for the Developers as well as the learners also.
Screenshot:
DB Connection:
<?php
$query1=mysql_connect("localhost","root","");
mysql_select_db("db_name",$query1);
?>
Style.css:
<style type="text/css"> .page { margin: -44px 17px 3px 166px; padding: 0;height: 29px; } .page li { list-style: none; display:inline-block; } .page li a, .current { display: block; padding: 5px; text-decoration: none; color: #blue; font-weight:bold margin: 33px 2px 2px; border:1px solid black; } .current{ display: block; padding: 5px; text-decoration: none; color: #FFF; border: 1px solid #000; font-size: 16px; background: #000; } .button { padding: 5px 15px; text-decoration: none; color: #F3F3F3; font-size: 13PX; border-radius: 2PX; margin: 0 4PX; display: block; margin: -7px 961px 13px 270px; padding: 7px 3px; } .button1{ text-decoration: none; margin: 10px 1136px -36px 84px; font-size: 13px; border-radius: 2px; display: block; padding: 6px 40px; } </style>
<body> <table width="60%" cellpadding="7" cellspacing="0" border="1" style="margin: 59px 0px 3px;
font-size:14px;"> <thead> <tr class="table_tr1"> <th>S.No</th> <th >Name</th> <th >Mobile_no</th> <th>Email_id</th> <th>City</th> <th>Message</th> <th>Created On</th> </tr> </thead> <?php $start=0; $limit=3; $rows=mysql_num_rows(mysql_query("select * from form")); $total=ceil($rows/$limit); if(isset($_GET['id'])) { $id=$_GET['id']; $start=($id-1)*$limit; if($id>1) { echo "<a href='?id=".($id-1)."' class='button1'><img src='arrow_left.png' width='22px'
height='22px'/></a>";
}
if($id!=$total)
{
echo "<a href='?id=".($id+1)."' class='button'><img src='arrow_right.png' width='22px'
height='22px'/></a>";
}
$i=($id-1)*$limit+1;
$query=mysql_query("select * from form LIMIT $start, $limit");
echo "<div>";
if($rows>0)
{
while($row=mysql_fetch_array($query))
{
$id=$row['id'];
$name=$row['name'];
$mobileno=$row['mobileno'];
//$seat_numbers = str_replace(",", ", ", $seat_numbers);
$email_id=$row['email_id'];
$starting_city=$row['starting_city'];
$message=$row['message'];
$createdon=$row['created_on'];
echo "<tr class='table_tr2' style='text-align:center;'>";
echo "<td>" . $i++. "</td>";
echo "<td>" . $name. "</td>";
echo "<td>" . $mobileno. "</td>";
echo "<td>" . $email_id. "</td>";
echo "<td>" . $starting_city. "</td>";
echo "<td>" . $message . "</td>";
echo "<td> " . $createdon ."</td>";
echo "</tr>";
}
}
else
{
echo "<tr>";
echo "<td align='center' style='font-weight: bold; font-size: 20px;color:#3399FF;
text-align:center;'>NO DATA FOUND</td>";
echo "</tr>";
echo "</table>";
}
}
$id=$_REQUEST['id'];
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>";
?>
</body>
</html>
Screenshot For Dispaly Results:
Database Structure:
-- -- Table structure for table `form` -- CREATE TABLE IF NOT EXISTS `form` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `mobileno` bigint(12) NOT NULL, `email_id` varchar(50) NOT NULL, `starting_city` varchar(100) NOT NULL, `message` longtext NOT NULL, `created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=137 ;
No comments:
Post a Comment