明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

模仿PHP寫的ASP分頁

[摘要]<%' 分頁程序' total_records 總記錄數(shù)' everypage_records 每頁顯示條數(shù)' current_page 當前頁數(shù)' url 要傳遞的url,這里可以含有要傳遞的變量,比如 "list.asp?" 或...

<%
' 分頁程序
' total_records 總記錄數(shù)
' everypage_records 每頁顯示條數(shù)
' current_page 當前頁數(shù)
' url 要傳遞的url,這里可以含有要傳遞的變量,比如 "list.asp?" 或者"list.asp?keyword=key&"
' 程序調(diào)用比較簡單,不過還是比PHP的麻煩,繼續(xù)努力中

sub show_page(total_records,everypage_records,current_page,url)

 if IsNumeric (total_records) then
  total_records=Int(total_records)
 else
  total_records=0
 end if
 
 if IsNumeric (everypage_records) then
  everypage_records=Int(everypage_records)
  if everypage_records<=0 then
   everypage_records=10
  end if
 else
  everypage_records=10
 end if
 
 if IsNumeric (current_page) then
  current_page=Int(current_page)
 else
  current_page=1
 end if
 
 '取總頁數(shù),即最后一頁
 if total_records mod everypage_records=0 then
  last_page=Int(total_records/everypage_records)
 else
  last_page=Int(total_records/everypage_records)+1
 end if
 
 '判斷 current_page 是否符合標準,并附值給page
 if current_page>=last_page then
  page=last_page
 elseif current_page<=1 then
  page=1
 else
  page=current_page
 end if
 
 '上一頁
 if page<=0 then
  prepg=0
 else
  prepg=page-1
 end if
 '下一頁
 if page=last_page then
  nextpg=0
 else
  nextpg=page+1
 end if
 
 '本頁開始記錄
 firstcount=prepg*everypage_records
 '本頁結(jié)束記錄
 if nextpg>=1 then
  lastcount=(nextpg-1)*everypage_records
 else
  lastcount=total_records
 end if
 '開始分頁導(dǎo)航條代碼
 pagenav=""
 pagenav1=""
 pagenav=pagenav&"顯示第<b>"&firstcount&"-"&lastcount&"</b>條記錄 共<b>"&total_records&"</b> 條記錄"
 pagenav1=pagenav1&"顯示第<b>"&firstcount&"-"&lastcount&"</b>條記錄 共<b>"&total_records&"</b> 條記錄"
 
 if last_page>1 then
 '當有前后頁時
 pagenav=pagenav&" <a href='"&url&"page=1'>首頁</a> "
 pagenav1=pagenav1&" <a href='"&url&"page=1'>首頁</a> "
 if prepg>=1 then
  pagenav=pagenav&" <a href='"&url&"page="&prepg&"'>前頁</a> "
  pagenav1=pagenav1&" <a href='"&url&"page="&prepg&"'>前頁</a> "
 else
  pagenav=pagenav&" 前頁 "
  pagenav1=pagenav1&" 前頁 "
 end if
 if nextpg>=1 then
  pagenav=pagenav&" <a href='"&url&"page="&nextpg&"'>后頁</a> "
  pagenav1=pagenav1&" <a href='"&url&"page="&nextpg&"'>后頁</a> "
 else
  pagenav=pagenav&" 后頁 "
  pagenav1=pagenav1&" 后頁 "
 end if
 pagenav=pagenav&" <a href='"&url&"page="&last_page&"'>尾頁</a> "
 pagenav1=pagenav1&" <a href='"&url&"page="&last_page&"'>尾頁</a> "
 
 pagenav=pagenav&"到第<input type=text name=text100 id=text100 value="&page&" size=3>頁<input type=button name=button100 value=go onclick='window.location="""&url&"page=""+text100.value'>"
 pagenav=pagenav&" 共 "&last_page&" 頁"

 pagenav1=pagenav1&"到第<input type=text name=text101 id=text101 value="&page&" size=3>頁<input type=button name=button101 value=go onclick='window.location="""&url&"page=""+text101.value'>"
 pagenav1=pagenav1&" 共 "&last_page&" 頁"
 end if

end sub
%>