模仿PHP寫的ASP分頁(yè)
發(fā)表時(shí)間:2024-02-02 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]<%' 分頁(yè)程序' total_records 總記錄數(shù)' everypage_records 每頁(yè)顯示條數(shù)' current_page 當(dāng)前頁(yè)數(shù)' url 要傳遞的url,這里可以含有要傳遞的變量,比如 "list.asp?" 或...
<%
' 分頁(yè)程序
' total_records 總記錄數(shù)
' everypage_records 每頁(yè)顯示條數(shù)
' current_page 當(dāng)前頁(yè)數(shù)
' url 要傳遞的url,這里可以含有要傳遞的變量,比如 "list.asp?" 或者"list.asp?keyword=key&"
' 程序調(diào)用比較簡(jiǎn)單,不過(guò)還是比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
'取總頁(yè)數(shù),即最后一頁(yè)
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 是否符合標(biāo)準(zhǔn),并附值給page
if current_page>=last_page then
page=last_page
elseif current_page<=1 then
page=1
else
page=current_page
end if
'上一頁(yè)
if page<=0 then
prepg=0
else
prepg=page-1
end if
'下一頁(yè)
if page=last_page then
nextpg=0
else
nextpg=page+1
end if
'本頁(yè)開(kāi)始記錄
firstcount=prepg*everypage_records
'本頁(yè)結(jié)束記錄
if nextpg>=1 then
lastcount=(nextpg-1)*everypage_records
else
lastcount=total_records
end if
'開(kāi)始分頁(yè)導(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
'當(dāng)有前后頁(yè)時(shí)
pagenav=pagenav&" <a href='"&url&"page=1'>首頁(yè)</a> "
pagenav1=pagenav1&" <a href='"&url&"page=1'>首頁(yè)</a> "
if prepg>=1 then
pagenav=pagenav&" <a href='"&url&"page="&prepg&"'>前頁(yè)</a> "
pagenav1=pagenav1&" <a href='"&url&"page="&prepg&"'>前頁(yè)</a> "
else
pagenav=pagenav&" 前頁(yè) "
pagenav1=pagenav1&" 前頁(yè) "
end if
if nextpg>=1 then
pagenav=pagenav&" <a href='"&url&"page="&nextpg&"'>后頁(yè)</a> "
pagenav1=pagenav1&" <a href='"&url&"page="&nextpg&"'>后頁(yè)</a> "
else
pagenav=pagenav&" 后頁(yè) "
pagenav1=pagenav1&" 后頁(yè) "
end if
pagenav=pagenav&" <a href='"&url&"page="&last_page&"'>尾頁(yè)</a> "
pagenav1=pagenav1&" <a href='"&url&"page="&last_page&"'>尾頁(yè)</a> "
pagenav=pagenav&"到第<input type=text name=text100 id=text100 value="&page&" size=3>頁(yè)<input type=button name=button100 value=go onclick='window.location="""&url&"page=""+text100.value'>"
pagenav=pagenav&" 共 "&last_page&" 頁(yè)"
pagenav1=pagenav1&"到第<input type=text name=text101 id=text101 value="&page&" size=3>頁(yè)<input type=button name=button101 value=go onclick='window.location="""&url&"page=""+text101.value'>"
pagenav1=pagenav1&" 共 "&last_page&" 頁(yè)"
end if
end sub
%>