动感首页更新实现之四 ------ 首页显示篇
发表于:2007-06-30来源:作者:点击数:
标签:
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(requ
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>
</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@#>>>分页 "
if CurrentPage<2 then
response.write "<font color=@#999966@#>首页 上一页</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=@#999966@#>下一页 尾页</font>"
else
response.write "<a href="&filename&"?page="&(CurrentPage+1)
response.write ">下一页</a> <a href="&filename&"?page="&n&">尾页</a>"
end if
response.write " 页次:<strong><font color=red>"&CurrentPage&"</font>/"&n&"</strong>页 "
response.write " 共<b>"&totalnumber&"</b>篇文章 <b>"&maxperpage&"</b>篇文章/页 "
response.write " 转到:<input class=TextBorder style=@#TEXT-ALIGN: center@# type=@#text@# name=@#page@# size=2 maxlength=10 class=smallInput value="¤tpage&">"
response.write " <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/
(待续)
原文转自:http://www.ltesting.net