hi friends,im new in php and need to this urgently , i got this code in net using sybase function and i change it to odbc because i working with sybase database this code already list the data nicely but the problem is when i click at one of the number page or next or previous link it will stay at page 1 please.....help me
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RC4PHP TEST</title>
</head>
<body>
<?php
$conn = odbc_connect("mydsn", "dba", "sql");
$sql="select * from tablename";
$qry = odbc_exec($conn,$sql);
$max = odbc_num_rows($qry);
$maxrec = 15; # control the no. of records per page
$currpg=1;
$postn=25;
$pgmax = 10; # control the paging number to be displayed
$const = $maxrec * $pgmax; # maximum no. of record count in a page (used in hyperlinks)
$remainder = bcmod($max,$maxrec); #determines if the maximum no. of query result is divisible by $maxrec
$max_no_page = ($max-$remainder)/$maxrec; #determines the maximum no. of pages in a query result
if($remainder > 0 and $max > $maxrec) ++$max_no_page;
#Record Loop Controller
#$startrec -- the starting position of the data or record to be fetched
#$endrec -- determines the last data or record to be fetched
$currpg='';
if($max < $maxrec){ # checks if the no. of query result is less than $maxrec
$startrec = 0; #sets the initial value of the $startrec and $endrec
$endrec = $max;
}
elseif($max > $maxrec){# checks if the no. of query result is greater than $maxrec
if($currpg == ""){ # sets the initial value of the $startrec and $endrec
$startrec = 0;
$endrec = $maxrec;
}
elseif($currpg != "" and $currpg != $max_no_page) { # sets the new value of the $startrec and $endrec
$startrec = $postn;
$endrec = $postn + $maxrec;
}
elseif ($currpg == $max_no_page){ # for correct display of the Last Records
$startrec = $postn;
$endrec = $max;
}
}
#End of Record Loop Controller
for ($i = $startrec; $i < $endrec; ++$i) {
if (!odbc_cursor ($qry, $i)) {
echo "Cannot seek to row $i\n";
continue;
}
if(!($row = odbc_fetch_object($qry)))
continue;
echo "$row->FullName $row->HomeAddress <br />\n"; # Displays the record selected from Database (i.e. depends on your SQL Query).
}
if ($max > $maxrec) { # checks if the query results return more than $maxrec
#Page Controller
#$start -- specify the starting point of Paging Display
#$end -- specify the end point of the Paging Display
#$currpg -- refers to the current page selected
#$prev -- previous 10 pages
#$next -- next 10 pages
#$first -- go to first page
#last -- go to last page
if ($currpg == "" and $max_no_page >= $pgmax){
$start = 1; # sets initial value of $start and $end
$end = $pgmax;
}
elseif ($currpg == "" and $max_no_page < $pgmax){
$start = 1; #sets initial value of $start and $end
$end = $max_no_page;
}
elseif ($currpg != "" and $currpg > $pgmax){ # sets the value $start and $end dynamically
#sets the $start value
$temp = bcmod($currpg,$pgmax);
if ($temp == 0){$start = ($currpg + 1) - $pgmax;}
else{$start = ($currpg + 1) - $temp;}
#sets the $end value
$temp = $max_no_page - bcmod($max_no_page,$pgmax); # was also used in Next & Last Page Link
if($currpg <= $temp) $end = $start + ($pgmax - 1);
elseif(($max_no_page - $currpg) < $pgmax) $end = $max_no_page; #value for the last batch of records
}
else{ # currpg is not null and less than $pgmax
$start = 1; #sets initial value for $start and $end
$end = $pgmax;
}
End of Page Controller
#######Retains the current record position that is to be fetched from the database
$postn=1;
if ($postn != "" and $postn >= $const)
{
$temp1 = bcmod($postn,$const);
$newtemp1 = ($postn-$temp1)/$const;
$pos = ($newtemp1 $const) - $maxrec;
}
elseif ($postn != ""){$pos = $postn - $maxrec;}
elseif($postn == "" and $postn >= $const)
{
$temp1 = bcmod($postn,$const);
$newtemp1 = ($postn-$temp1)/$const;
$pos = ($newtemp1 $const) - $maxrec;
}
#######End the current record retainer
#Previous & First Page Link
if($currpg > $pgmax){
$leaves = $start - 1; #value to be assigned to the currpg of Previous Link
echo " <a href=test.php>First</A> ";
echo " <a href=test.php?currpg=$leaves&postn=$pos>Previous</A> ";
}
#End of Previous & First Page Link
Paging Display (i.e. [ 1 2 3 . . .])
echo "[ ";
for ($pg = $start; $pg <= $end; ++$pg){
if($pg == 1){$pos = 0;}
else $pos = $pos + $maxrec;
if($start == $pg and $currpg == "") echo " $pg ";
elseif($pg == $currpg) echo " $pg ";
else{
echo " <a href=test.php?currpg=$pg&postn=$pos>$pg</A> ";
}
}
echo " ]";
end of paging Display
#Next & Last Page Link
$temp = bcmod($currpg,$pgmax);
if ($temp == 0){$temp = ($currpg + 1) - $pgmax;}
else{$temp = ($currpg + 1) - $temp;}
$temp = $max_no_page - $temp; # determines the starting position of the navigatinal control (i.e. [1 2 3 ...] )
1 -- denotes the starting position
if($temp >= $pgmax){
$pos = $pos + $maxrec;
echo " <a href=test.php?currpg=$pg&postn=$pos>Next</A> ";
$pos = $max - $remainder;
echo " <a href=test.php?currpg=$max_no_page&postn=$pos>Last</A> ";
}
#End of Next & Last Page Page Link
}
odbc_close($conn);
?>
</body>
</html>
thanks in advance