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 " ";
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>";
}
?>