Hi frns..
here i am going to do paging ...
upto now i got correctly what i mentioned(previous & next ) here...
but i need to add last and first also....
plz see this code with patience....
reply me asap....

<?php 
include("config.php");
$page_name="index.php";

$start=$_GET['start'];
 // To take care global variable if OFF
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}


$eu = ($start - 0);

if(!$limit > 0 ){ // if limit value is not available then let us use a default value
$limit = 10; // No of records to be shown per page by default.
}
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
if($area==""){
/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$query2=" SELECT * FROM resorts ORDER BY rname ASC";
$result3=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result3);

$query="SELECT * FROM resorts ORDER BY rname ASC limit $eu, $limit";
$row=mysql_query($query);
echo mysql_error();}
else{
/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$query2=" SELECT * FROM resorts where area='$area'";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);

$query="SELECT * FROM resorts where area='$area' limit $eu, $limit";
$row=mysql_query($query);
echo mysql_error();
}
while($rec=mysql_fetch_array($row))
{
$name=$rec['rname'];
$area=$rec['area'];
$address=$rec['address'];
$cuisine=$rec['cuisine'];
$timings=$rec['timings'];
?>
        <tr>
          <td height="30" id="td"><a href="pdetails.php?c=<?php echo $c; ?> & name=<?php echo $name; ?> & area=<?php echo $area; ?>"><?php echo $name; ?></a><a href="pdetails.php?name=<?php echo $name; ?> & c=<?php echo $c; ?>"></a></td>
          <td id="td"><?php echo $address; ?></td>
          <td id="td"><?php echo $cuisine; ?></td>
          <td id="td"><?php echo $timings; ?></td>
        </tr><?php } ?>
      </table>      
      <p>
        <?php
	
		if(isset($result2)){
echo "<table width='50%' align='right'><tr><td align='left' width='30%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) {
print "<a href='$page_name?start=$back&limit=$limit&area=$area & c=$c'> PREV </a>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume; $i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i&limit=$limit&area=$area & c=$c'> $l </a> ";
}
else { echo "$l";} /// Current page is not displayed as link and given font color red
$l=$l+1;
}


echo "</td><td align='right' width='30%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) {
print "<a href='$page_name?start=$next&limit=$limit&area=$area & c=$c'> NEXT </a>";}
echo "</td></tr></table>";

}

else{

echo "<table width='50%' align='right'><tr><td align='left' width='30%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) {
print "<a href='$page_name?start=$back&limit=$limit'> PREV </a>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu && $l<=3  ){

echo " <a href='$page_name?start=$i&limit=$limit'> $l </a> ";
}

elseif($i <> $eu){echo " <a href='$page_name?start=$i&limit=$limit'></a> "; }
else { 
echo "&nbsp;&nbsp;";
echo "$l";
} /// Current page is not displayed as link and given font color red
$l=$l+1;
}


echo "</td><td align='right' width='30%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) {
print "<a href='$page_name?start=$next&limit=$limit'> NEXT </a>";}
echo "</td></tr></table>";
}
 ?>
<?php
$items = array("red","yellow",
"pink","green",
"purple","blue",
"orange","opal",
"ruby","brown",
"bronze","copper",
"ginger","tope",
"orange","light blue",
"light green","dark yellow",
"grey","black",
"white","gold",
"silver");


$thispage = $PHP_SELF ;
$num = count($items); // number of items in list
$per_page = 2; // Number of items to show per page
$showeachside = 5 //  Number of items to show either side of selected page


if(empty($start))$start=0;  // Current start position


$max_pages = ceil($num / $per_page); // Number of pages
$cur = ceil($start / $per_page)+1; // Current page number
?>
<style type="text/css">
<!--
.pageselected {
color: #FF0000;
font-weight: bold;
}
-->
</style>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0" class="PHPBODY">
<tr>
<td width="99" align="center" valign="middle" bgcolor="#EAEAEA">
<?php
if(($start-$per_page) >= 0)
{
$next = $start-$per_page;
?>
<a href="<?php print("$thispage".($next>0?("?start=").$next:""));?>"><<</a>
<?php
}
?>
</td>
<td width="201" align="center" valign="middle" class="selected">
Page <?php print($cur);?> of <?php print($max_pages);?><br>
( <?php print($num);?> records )
</td>
<td width="100" align="center" valign="middle" bgcolor="#EAEAEA">
<?php
if($start+$per_page<$num)
{
?>
<a href="<?php print("$thispage?start=".max(0,$start+$per_page));?>">&gt;&gt;</a>
<?php
}
?>
</td>
</tr>
<tr><td colspan="3" align="center" valign="middle">&nbsp;</td></tr>
<tr>
<td colspan="3" align="center" valign="middle" class="selected">
<?php
$eitherside = ($showeachside * $per_page);
if($start+1 > $eitherside)print (" .... ");
$pg=1;
for($y=0;$y<$num;$y+=$per_page)
{
$class=($y==$start)?"pageselected":"";
if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside)))
{
?>
&nbsp;<a class="<?php print($class);?>" href="<?php print("$thispage".($y>0?("?start=").$y:""));?>"><?php print($pg);?></a>&nbsp;
<?php
}
$pg++;
}
if(($start+$eitherside)<$num)print (" .... ");
?>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<?php
for($x=$start;$x<min($num,($start+$per_page)+1);$x++)print($items[$x]."<br>");
?>
</td>
</tr>
</table>

source

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.