首页  ·  知识 ·  编程语言
模仿PHP写的ASP分页
佚名  http://phpup.com/  ASP  编辑:dezai  图片来源:网络
%' 分页程序' total_records 总记录数' everypage_records 每页显示条数' current_page 当前页数' url 要传递的url,这里可以含有

<%
' 分页程序
' 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&"显示第"&firstcount&"-"&lastcount&"条记录 共"&total_records&" 条记录"
 pagenav1=pagenav1&"显示第"&firstcount&"-"&lastcount&"条记录 共"&total_records&" 条记录"
 
 if last_page>1 then
 '当有前后页时
 pagenav=pagenav&" 首页 "
 pagenav1=pagenav1&" 首页 "
 if prepg>=1 then
  pagenav=pagenav&" 前页 "
  pagenav1=pagenav1&" 前页 "
 else
  pagenav=pagenav&" 前页 "
  pagenav1=pagenav1&" 前页 "
 end if
 if nextpg>=1 then
  pagenav=pagenav&" 后页 "
  pagenav1=pagenav1&" 后页 "
 else
  pagenav=pagenav&" 后页 "
  pagenav1=pagenav1&" 后页 "
 end if
 pagenav=pagenav&" 尾页 "
 pagenav1=pagenav1&" 尾页 "
 
 pagenav=pagenav&"到第"
 pagenav=pagenav&" 共 "&last_page&" 页"

 pagenav1=pagenav1&"到第"
 pagenav1=pagenav1&" 共 "&last_page&" 页"
 end if

end sub
%>

本文作者:佚名 来源:http://phpup.com/
CIO之家 www.ciozj.com 微信公众号:imciow
    >>频道首页  >>网站首页   纠错  >>投诉
版权声明:CIO之家尊重行业规范,每篇文章都注明有明确的作者和来源;CIO之家的原创文章,请转载时务必注明文章作者和来源;
延伸阅读