欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

index.asp

读入数据库链接!

<!–#include file="articleconn.asp"–>

<html>

<%

每页最大显示数为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

%>

<head>

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<title>asp动感在线</title>

<meta name="generator" content="microsoft frontpage 3.0">

<link rel="stylesheet" href="../css/style.css">

</head>

<body bgcolor="#ffffff">

<table width="90%" cellpadding="0" cellspacing="0" align="center">

<tr>

<td colspan="3" height="203">

<table border="1" width="100%" bordercolorlight="#000000" bordercolordark="#ffffff" cellpadding="0" cellspacing="0" align="center">

<tr bgcolor="#acd6ff">

<td width="100%" height="20">

<p align="center"><font color="#000000"><b>站 务 公 告</b></font>

</td>

</tr>

<tr>

<td width="100%" height="152">

<form method="post" action="index.asp">

<br>

<font color="#ff0000"> </font>

<table border=0 cellpadding=0 cellspacing=0 width="54%" align="center">

<tr>

<td valign=center colspan="3" align="right">

<div align="center">查询关键字<font color="#ff0000"><%=keyword%></font>

</div>

</td>

</tr>

<tbody>

<tr>

<td width="27%" align="right">请输入搜索字符: </td>

<td valign=center width="54%" align="center">

<input class=textborder maxlength=25

name=keyword size=26>

&nbsp;&nbsp;</td>

<td valign=buttom width="19%" align="left">

<input alt=站内搜索 border=0

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

</td>

</tr>

</tbody>

</table>

</form>

<p align="left"><%

打开数据库内容安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 "<p align=center> 还 没 有 任 何 文 章</p>"

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

%> </p>

<table border="0" cellspacing="0" bordercolorlight="#000000" bordercolordark="#ffffff" cellpadding="0" vspace="10" hspace="40" align="center" width="80%">

循环输出数据库中的数据,一直到结束!

<tr> <%do while not rs.eof%>

<tr>

<td colspan="2"><font color="#000099">○</font> <a <%rs("xxx")%>就是数据库要显示的内容是编写asp的关键

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

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

<i><font color="#ff0000">(<%=rs("dateandtime")%>)</font></i></td>

</tr>

<tr>

<td width="550" colspan="2"><%=rs("content")%> <br>

<br>

</td>

</tr>

<% i=i+1

if i>=maxperpage then exit do

rs.movenext

loop

%>

</table>

<%

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 "<form method=post action="&filename&">"

response.write "<p align=center valign=bottom>&gt;&gt;分页&nbsp;"

if currentpage<2 then

response.write "<font color=999966>首页 上一页</font>&nbsp;"

else

response.write "<a href="&filename&"?page=1&>首页</a>&nbsp;"

response.write "<a href="&filename&"?page="&currentpage-1&">上一页</a>&nbsp;"

end if

if n-currentpage<1 then

response.write "<font color=999966>下一页 尾页</font>"

else

response.write "<a href="&filename&"?page="&(currentpage+1)

response.write ">下一页</a> <a href="&filename&"?page="&n&">尾页</a>"

end if

response.write "&nbsp;页次:<strong><font color=red>"&currentpage&"</font>/"&n&"</strong>页 "

response.write "&nbsp;共<b>"&totalnumber&"</b>篇文章 <b>"&maxperpage&"</b>篇文章/页 "

response.write " &nbsp;转到:<input class=textborder style=text-align: center type=text name=page size=2 maxlength=10 class=smallinput value="&currentpage&">"

response.write " &nbsp;&nbsp;<input alt=页面跳转 name=submit src=../images/goto.gif type=image></span></p></form>"

end function

%> </td>

</tr>

</table>

</td>

</tr>

</table>

版权信息!不作解释了!

<p align="center">《<a href="http://asp.on.net.cn/" target="_blank">asp动感在线</a>》编辑制作</p>

</body>

</html>

大家注意的是两点:

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

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

作者:阿喔 出处:<asp动感在线> http://asp.on.net.cn/

(待续)

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 动感首页更新实现之四 —— 首页显示篇
分享到: 更多 (0)