hi, i made this script i think this will help all others as well i am not very good at PHP soo if you find anything that you things you can make better then plz do so and give me a copy as well so that i can also benefit. one problem this function was made for MSSQL will need some changes and will work for mysql as well. if you change can make this script work for mysql email me the script so that i can use this
here is the code //========================================================================== ==== /* nTNOP :total no of pages, strUrl :url of the page where the links should point, nCP :current page that is showing nSNP :Show Next Previous nSPL :Show Pages As Links nNOPTS :no of pages to show only applicable if nSPL is TRUE nNPT : next previous type : 1 for text ( << ) ( >> ) : 2 for image strNCOI : Next Character Or Image (Character if nNPT==1 And Image If nNPT==2) strPCOI : Previous Character Or Image (Character if nNPT==1 And Image If nNPT==2) strQSTR : Query string that we want to move along the links without & sign script will add this */ function ShowNavLink($nTNOP,$strUrl='',$nCP,$nSNP=TRUE,$nSPL=TRUE,$nNOPTS=15,$nNPT=1, $strNCOI='>>',$strPCOI='<<',$strQSTR='') { if ($nTNOP < 1) { return FALSE; } if (empty($strQSTR)) { $strQSTR=''; } else $strQSTR="&".$strQSTR; if (empty($strUrl)) { $strUrl=GetPageName(); } if (empty($nSNP)) { $nSNP=TRUE; } if (empty($nSPL)) { $nSPL=TRUE; } if (empty($nNOPTS)) { $nNOPTS=15; } if (empty($nNPT)) { $nNPT=1; } if (empty($strNCOI)) { $strNCOI='>>'; } if (empty($strPCOI)) { $strPCOI='<<'; } if ($nTNOP==1) // if there is only one page so no next previous link { $SN=FALSE; $SP=FALSE; } elseif ($nTNOP == $nCP) // if we are on the last page { $SN=FALSE; $SP=TRUE; } elseif ($nCP == 1) // if current page is the first page { $SN=TRUE; $SP=FALSE; } elseif ($nCP > 1 || $nCP < $nTNOP) // if we are in between the first page and the last page { $SN=TRUE; $SP=TRUE; } if ($nNPT==2) { $strNCOI="<img src=\"$strNCOI\" border=\"0\" hspace=\"5\">"; $strPCOI="<img src=\"$strPCOI\" border=\"0\" hspace=\"5\">"; } if ($nTNOP > $nNOPTS) // this means that we have a larger result { if ($nCP >=1 && $nCP <= CEIL($nNOPTS/2)) { $nStart=1; $nEnd=$nNOPTS; } elseif (($nCP >=($nTNOP-CEIL($nNOPTS/2))) && $nCP <= $nTNOP) { $nStart=$nTNOP-$nNOPTS; $nEnd=$nTNOP; } else { $nStart=$nCP - (CEIL($nNOPTS/2)) + 1; $nEnd=$nCP + (CEIL($nNOPTS/2)) - 1; } } else { $nStart=1; $nEnd=$nTNOP; } echo "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n"; echo "<tr>\n"; echo "<td>\n"; echo "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n"; echo "<tr>\n"; echo "<td>\n"; echo "Showing Page ".$nCP." Of Total ".$nTNOP; echo "\n</td>\n"; echo "</tr>\n"; echo "</table>\n"; echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td align=\"center\">\n"; echo "<table>\n"; echo "<tr>\n"; if ($SP) { echo "<td>\n"; echo "<a href=\"".$strUrl."?nCP=".($nCP-1).$strQSTR."\">$strPCOI</a>\n"; echo "</td>\n"; } for ($i=$nStart;$i<=$nEnd;$i++) { echo "<td>\n"; if ($i==$nCP) echo "<a href=\"".$strUrl."?nCP=$i".$strQSTR."\"><font color=\"red\">".$i."</font></a>\n"; else echo "<a href=\"".$strUrl."?nCP=$i".$strQSTR."\">".$i."</a>\n"; echo "</td>\n"; } if ($SN) { echo "<td>\n"; echo "<a href=\"".$strUrl."?nCP=".($nCP+1).$strQSTR."\">$strNCOI</a>\n"; echo "</td>\n"; } echo "</tr>\n"; echo "</table>\n"; echo "</td>"; echo "</tr>\n"; echo "</table>\n"; } function NavPageCount($nRPP=20,$strTableName,$strFieldSet='*',$strWhere='') { $strQuery="SELECT COUNT(".$strFieldSet.") AS nCount FROM ".$strTableName." WHERE ".$strWhere; $nResult=DoQuery($strQuery); $nCount=0 + Get("nCount",$nResult); [EMAIL PROTECTED]($nCount/$nRPP); return $nCount; } function Navigation($nRPP=20,$nCP=1,$strTableName,$strFieldSet='*',$strSortOn='',$str Where='') { if (empty($strWhere)) { $strWhere=''; $strNewWhere=''; } else $strNewWhere=" AND ".$strWhere; $strQuery="SELECT TOP ".$nRPP." ".$strFieldSet." FROM ".$strTableName." WHERE ".$strSortOn." NOT IN (SELECT TOP " .($nRPP * ($nCP -1)) ." ".$strSortOn." FROM ".$strTableName." WHERE ".$strWhere." ORDER BY ".$strSortOn.") ".$strNewWhere." ORDER BY ".$strSortOn; $nResult=DoQuery($strQuery); return $nResult; } here is an examle of using this if (empty($nRPP)) { $nRPP=10; } if (empty($nCP)) { $nCP=1; } $nResult=Navigation($nRPP,$nCP,"tblSMov MS,tblMov MOV",'MOV.*',"MOV.mov_name","MOV.mov_id=MS.smv_mov_id",''); echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">"; while (odbc_fetch_row($nResult)) { GET ALL THE DATA HERE } //************************************************************************** ********************/ // we are going to make a navigation bar under these records $nTNOP=NavPageCount($nRPP,"tblSMov MS,tblMov MOV",'MOV.mov_id',"MOV.mov_id=MS.smv_mov_id"); $strQSTR="Id=".$Id."; ShowNavLink($nTNOP,'',$nCP,TRUE,TRUE,15,1,'>>','<<',$strQSTR); THATS IT. if you want to know anything that is puzleing you plz feel free.to ask. Haseeb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php