繁体中文
设为首页
加入收藏
当前位置:ASP技术首页 >> 打印相关 >> 动感首页更新实现之四 ------ 首页显示篇

动感首页更新实现之四 ------ 首页显示篇

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:19  文字大小:【】【】【
简介:index.asp '读入数据库链接! <!--#include file="articleconn.asp"--> <html> <% '每页最大显示数为20 const MaxPerPage=20 dim totalPut dim CurrentPage dim TotalP...
关键字:首页 动感 更新

index.asp

'读入数据库链接!

<%

'每页最大显示数为20

const MaxPerPage=20

dim totalPut

dim CurrentPage

dim TotalPages

dim i,j

dim typename

dim keyword

keyword=trim(request("keyword"))

if not isempty(request("page")) then

currentPage=cint(request("page"))

else

currentPage=1

end if

%>

ASP动感在线

站 务 公 告


查询关键字<%=keyword%>

请输入搜索字符:

name=keyword size=26>

name=submit src="../images/search.gif" type=image>

<%

'打开数据库内容安ARTICLEID的倒数排列!

'title like '%"&keyword&"%' 为对搜索字的查找,空者表示全部!

sql="select * from learning where title like '%"&keyword&"%' order by articleid desc"

dim sql,rs

Set rs= Server.CreateObject("ADODB.Recordset")

rs.open sql,conn,1,1

'判断数据库是否为空!如果为空显示'还 没 有 任 何 文 章'

if rs.eof and rs.bof then

response.write "

还 没 有 任 何 文 章

"

else

'下面是对文章数,每页显示数的判断!大家可作其它程序的参考!!

totalPut=rs.recordcount

totalPut=rs.recordcount

if currentpage<1 then

currentpage=1

end if

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

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%>

<% i=i+1

if i>=MaxPerPage then exit do

rs.movenext

loop

%>

就是数据库要显示的内容是编写ASP的关键

'这个动作是对程序的目的,即得出显示结果!

href="<%=rs("url")%>" target="_blank"><%=rs("title")%>

(<%=rs("dateandtime")%>)

<%=rs("content")%>


<%

end sub

'大家看到的上页下页就是从这里得到的.可作其它程序的参考!

function showpage(totalnumber,maxperpage,filename)

dim n

if totalnumber mod maxperpage=0 then

n= totalnumber \ maxperpage

else

n= totalnumber \ maxperpage+1

end if

response.write "

"

response.write "

>>分页 "

if CurrentPage<2 then

response.write "首页 上一页 "

else

response.write "首页 "

response.write "上一页 "

end if

if n-currentpage<1 then

response.write "下一页 尾页"

else

response.write "下一页 尾页"

end if

response.write " 页次:"&CurrentPage&"/"&n&"页 "

response.write " 共"&totalnumber&"篇文章 "&maxperpage&"篇文章/页 "

response.write " 转到:"

response.write "

"

end function

%>

'版权信息!不作解释了!

ASP动感在线》编辑制作

大家注意的是两点:

1.个位可参照上面的程序举一反三!

2.<%=rs("xxx")及显示你txturl,txttitle等的内容,这是学ASP关键所在,这一点如果明白了!学ASP差不多到了一个新的境界!

作者:阿喔 出处: http://asp.on.net.cn/

(待续)

责任编辑:admin
相关文章