Pagination in PHP
Pagination in PHP
- Pagination in PHP
- Here suppose you have large data in table and when you fetch those data it will look like
(Without Pagination)
- In PHP it is possible to use pagination. (With Pagination)
- Here With pagination it will look like above picture.
Let's Start the Program of Pagination in PHP
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("test"); //Database name
$nor=5; //Number of record which we want to display at one time
if(isset($_GET['id']))
{
$cpage=$_GET['id'];
}
else
{
$cpage=1;
}
if(isset($_GET['id']))
{
$cpage=$_GET['id'];
}
$offset=($cpage-1)*$nor;
echo '<div align=center>';
$qu="select * from demo Limit $offset,$nor";
$res=mysql_query($qu);
echo '<table border=2><tr><td>Name</td><td>Rollno</td></tr>';
while($row=mysql_fetch_array($res))
{
echo '<tr><td>'.$row['name'].'</td>';
echo '<td>'.$row['roll'].'</td></tr>';
}
$qu1="select * from demo";
$res1=mysql_query($qu1);
$c=mysql_num_rows($res1);
$n=ceil($c/$nor);
if($cpage==1)
{
echo '<br><br><br>';
echo ' FIRST';
}
else
{
echo '<a href=paging.php?id=1> First </a>';
}
if($cpage!=1)
{
$n=$cpage-1;
echo "<a href=paging.php?id=$n>Prev</a>";
}
for($i=1;$i<$n;$i++)
{
if($i==$cpage)
{
echo"<a> ".$i."</a> ";
}
else
{
echo '<a href=paging.php?id='.$i.'> '.$i.'</a>';
}
}
if($cpage!=$nor)
{
$n=$cpage+1;
echo "<a href=paging.php?id=$n> Next</a>";
}
echo '</div>';
?>
what does nbsp mean in this syntanx?
ReplyDeleteit is used for space in html
ReplyDeleteI will suggest you my friend to give source in the form of zip file because there always remain a confusion of the logic .....
ReplyDelete