Hi All,
I have a Pagination script that works wonderfully when the user doesn't select a filter (by date or community). Yet when the user wants to filter the results by date or community, I get the correct initial return, but upon clicking "next", I'm returned all of the results again (no filter). Is there some way to make the hyperlinks distinguish between queries? Below is some code, but it's really long, so I'll snip the bulk:
<%
//Set the page size
$PageSize = 10;
$StartRow = 0;
//Set the page no
if(empty($GET['PageNo'])){
if($StartRow == 0){
$PageNo = $StartRow + 1;
}
}else{
$PageNo = $GET['PageNo'];
$StartRow = ($PageNo - 1) * $PageSize;
}
//Set the counter start
if($PageNo % $PageSize == 0){
$CounterStart = $PageNo - ($PageSize - 1);
}else{
$CounterStart = $PageNo - ($PageNo % $PageSize) + 1;
}
//Counter End
$CounterEnd = $CounterStart + ($PageSize - 1);
?>
<html>
// IF NO SORT *
if(!$btnSort){
$TRecord = mysql_query("SELECT from contactB");
$result = mysql_query("SELECT from contactB LIMIT $StartRow,$PageSize");
//Total of record
$RecordCount = mysql_num_rows($TRecord);
//Set Maximum Page
$MaxPage = $RecordCount % $PageSize;
if($RecordCount % $PageSize == 0){
$MaxPage = $RecordCount / $PageSize;
}else{
$MaxPage = ceil($RecordCount / $PageSize);
}
?>
TABLE OUTPUT ...snip
<?
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$bil = $i + ($PageNo-1)*$PageSize;
...
...snip
?>
TABLE OUTPUT ...snip
<?php
$i++;
}
//Print First & Previous Link is necessary
if($CounterStart != 1){
$PrevStart = $CounterStart - 1;
print "<a href=view_pag.php?PageNo=1>First </a>: ";
print "<a href=view_pag.php?PageNo=$PrevStart>Previous </a>";
}
print " [ ";
$c = 0;
//Print Page No
for($c=$CounterStart;$c<=$CounterEnd;$c++){
if($c < $MaxPage){
if($c == $PageNo){
if($c % $PageSize == 0){
print "$c ";
}else{
print "$c ,";
}
}elseif($c % $PageSize == 0){
echo "<a href=view_pag.php?PageNo=$c>$c</a> ";
}else{
echo "<a href=view_pag.php?PageNo=$c>$c</a> ,";
}//END IF
}else{
if($PageNo == $MaxPage){
print "$c ";
break;
}else{
echo "<a href=view_pag.php?PageNo=$c>$c</a> ";
break;
}//END IF
}//END IF
}//NEXT
echo "] ";
if($CounterEnd < $MaxPage){
$NextPage = $CounterEnd + 1;
echo "<a href=view_pag.php?PageNo=$NextPage>Next</a>";
}
//Print Last link if necessary
if($CounterEnd < $MaxPage){
$LastRec = $RecordCount % $PageSize;
if($LastRec == 0){
$LastStartRecord = $RecordCount - $PageSize;
}
else{
$LastStartRecord = $RecordCount - $LastRec;
}
print " : ";
echo "<a href=view_pag.php?PageNo=$MaxPage>Last</a>";
}
//* ELSE THE USER IS FILTERING RESULTS
}
elseif($btnSort){
new SQL statement based upon date or community
same Previous/Next script below OUTPUT
}
?>
Sorry for the mess, but my second SQL query is quite long, with a dynamic WHERE clause dependent upon what is clicked.
The end result is that the unfiltered return works perfectly. The initial return on the filter is fine, but when the user clickes "page 2" or "next", I get the first SQL query back.
Thanks for any help!!!
Geogal