<%
' 分頁程序
' total_records 總記錄數
' everypage_records 每頁顯示條數
' current_page 目前頁數
' url 要傳遞的url,這裡可以含有要傳遞的變量,例如"list.asp?" 或"list.asp?keyword=key&"
' 程式呼叫比較簡單,不過還是比PHP的麻煩,繼續努力中
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
'取總頁數,即最後一頁
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
'本頁結束記錄
if nextpg>=1 then
lastcount=(nextpg-1)*everypage_records
else
lastcount=total_records
end if
'開始分頁導覽條代碼
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
%>