选择显示字体大小

用asp做一个分页程序

     用asp做一个分页程序
  wodeail·cpcw
  
    你是否为了你的站点文章过多而反复做链接上一页、下一页这些烦琐的工作发愁呢?现在有了asp,只要你的主页支持asp,你就可以很简单的实现对文章的管理了,排序、链接、显示这些工作都让asp去完成吧!这么轻松的主页维护,你是不是也想试一试呢?
  
  请看以下实现asp分页程序的代码:
  
  <anguage="vbscript"
  
  dim conn
  
  dim connstr
  
  dim totalput
  
  dim currentpage
  
  dim totalpages
  
  dim i,j
  
  dim sql
  
  dim rs
  
  on error resume next
  
  '打开数据库
  
  connstr="dbq="+server.mappath("book.mdb")+";defaultdir=;driver={microsoft access driver (*.mdb)};"
  
  set conn=server.createobject("adodb.connection")
  
  conn.open connstr
  
  set rs=server.createobject("adodb.recordset")
  
  '定义每页文章显示数
  
  const maxperpage=18
  
  if not isempty(request("page")) then
  
  currentpage=cint(request("page"))
  
  else
  
  currentpage=1
  
  end if
  
  sql="select * from learning order by articleid desc"
  
  set rs= server.createobject("adodb.recordset")
  
  rs.open sql,conn,1,1
  
  if rs.eof and rs.bof then
  
  response.write "<p align='center'> 还 没 有 任 何 文 章</p>"
  
  else
  
  '数据库中文章数totalput
  
  totalput=rs.recordcount
  
  if currentpage<1 then
  
  currentpage=1
  
  end if
  
  '统计总页数currentpage
  
  if (currentpage-1)*maxperpage>totalput then
  
  if (totalput mod maxperpage)=0 then
  
  currentpage= totalput \ maxperpage
  
  else
  
  currentpage= totalput \ maxperpage + 1
  
  end if
  
  end if
  
  if currentpage=1 then
  
  showpage totalput,maxperpage,"index.asp"
  
  showcontent
  
  showpage totalput,maxperpage,"index.asp"
  
  else
  
  if (currentpage-1)*maxperpage<totalput then
  
  rs.move (currentpage-1)*maxperpage
  
  dim bookmark
  
  bookmark=rs.bookmark
  
  showpage totalput,maxperpage,"index.asp"
  
  showcontent
  
  showpage totalput,maxperpage,"index.asp"
  
  else
  
  currentpage=1
  
  showpage totalput,maxperpage,"index.asp"
  
  showcontent
  
  showpage totalput,maxperpage,"index.asp"
  
  end if
  
  end if
  
  rs.close
  
  end if
  
  set rs=nothing
  
  conn.close
  
  set conn=nothing
  
  sub showcontent
  
  dim i
  
  i=0
  
  do while not rs.eof
  
  >
  
  '选择显示数据库内容
  
  <a href="openarticle.asp?id=<=rs("articleid")>"><=rs("title")></a>[点击:<=rs("hits")>]<br>
  
  <
  
  '当显示记录大于maxperpage时结束这页
  
  i=i+1
  
  if i>=maxperpage then exit do
  
  rs.movenext
  
  loop
  
  end sub
  
  function showpage(totalnumber,maxperpage,filename)
  
  '求出当每页18篇文章时总共的页数
  
  dim n
  
  if totalnumber mod maxperpage=0 then
  
  n= totalnumber \ maxperpage
  
  else
  
  n= totalnumber \ maxperpage+1
  
  end if
  
  response.write "<form method=post action="&filename&">"
  
  response.write "<p align='center'><font color='#000080'>>>分页</font> "
  
  '显示页数链接的条件
  
  if currentpage<2 then
  
  response.write "<font color='#000080'>首页 上一页</font> "
  
  else
  
  response.write "<a href="&filename&"?page=1&>首页</a> "
  
  response.write "<a href="&filename&"?page="&currentpage-1&">上一页</a> "
  
  end if
  
  if n-currentpage<1 then
  
  response.write "<font color='#000080'>下一页 尾页</font>"
  
  else
  
  response.write "<a href="&filename&"?page="&(currentpage+1)
  
  response.write ">下一页</a> <a href="&filename&"?page="&n&">尾页</a>"
  
  end ifc
  
  response.write "<font color='#000080'> 页次:</font><strong><font color=red>"&currentpage&"</font><font color='#000080'>/"&n&"</strong>页</font>"
  
  response.write "<font color='#000080'> 共<b>"&totalnumber&"</b>篇文章 <b>"&maxperpage&"</b>篇文章/页</font>"
  
  response.write " <font color='#000080'>转到:</font><input type='text' name='page' size=4 maxlength=10 class=smallinput value="¤tpage&">"
  
  response.write "<input class=buttonface type='submit' value=' goto ' name='cndok'></span></p></form>"
  
  end function
  
  >
  
    以上代码很简单的就实现了asp网页的多种分页功能,不论是对浏览者还是管理者都能很方便的浏览和管理,我只在相关部分作了一些解释,象这个asp程序还必须有数据库的支持才可以,关于数据库的问题我就不详述了,具体的实例大家可以看看我的主页(http://aasp.yeah.net)上的文章管理程序,另外还有具体的程序下载!  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons