動感首頁更新完成之4 ------ 首頁顯示篇
發(fā)表時間:2024-02-16 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]index.asp '讀入數(shù)據(jù)庫鏈接! <!--#include file="articleconn.asp"--> <html> <% '每頁最大顯示數(shù)為20 const MaxPerPage=20 dim totalPut di...
index.asp
'讀入數(shù)據(jù)庫鏈接!
<!--#include file="articleconn.asp"-->
<html>
<%
'每頁最大顯示數(shù)為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>站 務(wù) 公 告</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">查詢關(guān)鍵字<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=站內(nèi)搜索 border=0
name=submit src="/article/UploadPic/200671952024896.gif" type=image>
</td>
</tr>
</tbody>
</table>
</form>
<p align="left"><%
'打開數(shù)據(jù)庫內(nèi)容安ARTICLEID的倒數(shù)排列!
'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
'判斷數(shù)據(jù)庫是否為空!如果為空顯示'還 沒 有 任 何 文 章'
if rs.eof and rs.bof then
response.write "<p align='center'> 還 沒 有 任 何 文 章</p>"
else
'下面是對文章數(shù),每頁顯示數(shù)的判斷!大家可作其它程序的參考!!
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%">
'循環(huán)輸出數(shù)據(jù)庫中的數(shù)據(jù),一直到結(jié)束!
<tr> <%do while not rs.eof%>
<tr>
<td colspan="2"><font color="#000099">○</font> <a '<%rs("xxx")%>就是數(shù)據(jù)庫要顯示的內(nèi)容是編寫ASP的關(guān)鍵
'這個動作是對程序的目的,即得出顯示結(jié)果!
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 " 轉(zhuǎn)到:<input class=TextBorder style='TEXT-ALIGN: center' type='text' name='page' size=2 maxlength=10 class=smallInput value="¤tpage&">"
response.write " <input alt=頁面跳轉(zhuǎn) name='submit' src='http://www.okasp.com/images/goto.gif' type='image'></span></p></form>"
end function
%> </td>
</tr>
</table>
</td>
</tr>
</table>
'版權(quán)信息!不作解釋了!
<p align="center">《<a target="_blank">ASP動感在線</a>》編輯制作</p>
</body>
</html>
大家注意的是兩點:
1.個位可參照上面的程序舉一反三!
2.<%=rs("xxx")及顯示你txturl,txttitle等的內(nèi)容,這是學(xué)ASP關(guān)鍵所在,這一點如果明白了!學(xué)ASP差不多到了一個新的境界!
(出處:熱點網(wǎng)絡(luò))