ASP advanced article online Management Update (8)

Source: Internet
Author: User
Tags date define exit chr empty goto include microsoft frontpage
After the addition of the article, save, display, so now it's time to talk about the management of the display of the main page, that is, to display the title of all articles connected to facilitate the viewer to find articles, it should have the function: Display all the article title connection, add date, browse times and other information, but also must provide paging function, Otherwise, the title of so many articles in a page are displayed, it will be very time-consuming and inconvenient to browse, in addition because this program here combined with the article column search function, so here will also be introduced.

The following is a detailed introduction to the main page of the index.asp of these functions of the implementation process and its specific functions:

"Establish a database connection
<!--#include file= "conn.asp"-->

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>asp Special Section </title>
<meta name= "generator" content= "Microsoft FrontPage 3.0" >
<link rel= "stylesheet" type= "Text/css" href= "Style.css" >
<script language= "JavaScript" >
function popwin2 (path)
{window.open (Path, "", "Height=450,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no, Location=no ");
}
</script>
<%

"Define the maximum article title per page maxperpage, you can modify the number here to achieve your best display effect
Const MAXPERPAGE=18
Dim totalput
Dim currentpage
Dim totalpages
Dim i,j

"If the returned page information is empty, that is, if you enter index.asp directly, then use the first page of the pages defined here
If not IsEmpty (Request ("page") Then
Currentpage=cint (Request ("page")
Else
Currentpage=1
End If
Dim sql
Dim rs
Dim Rstype
Dim typesql
Dim typeid,typename

"If the returned column information is empty, then use the column defined here, where the third column is specified
If not IsEmpty (Request ("typeID")) Then
Typeid=request ("typeID")
Else
Typeid=3
End If

"By returning the column typeid number, open the database to display the specified column, and give the value to typename
Set Rstype=server.createobject ("Adodb.recordset")
Typesql= "SELECT * from type where typeid=" &cstr (typeid)
Rstype.open typesql,conn,1,1
Typename=rstype ("type")
Rstype.close
%>

<body>
<div align= "center" ><center>

<table border= "0" width= "0" cellpadding= "0" >
<tr>
&LT;TD width= "100%" style= Border-left:thin dotted rgb (0,128,0); Border-right:thin dotted rgb (0,128,0) "><p align=" center "><br>

"Display column information, when you click on any of the columns, in the TypeName position will show the relevant information, there is no use of automatic column display mode is considered the display of the page, and the use of manually added mode, to use automatic mode, write it yourself: I believe you learn to now, I can't even make this up!
Dynamic Network ASP Skills >><font color= "#FF0000" ><%response.write "" &typename& ""%></font><br >
<a href= "index.asp?typeid=1" >asp faq</a>|<a href= "index.asp?typeid=2" >ASP components </a> |<a href = "index.asp?typeid=3" >asp Digest </a>|<a href= "index.asp?typeid=4" >asp instance </a>|<a href= " Index.asp?typeid=5 ">asp Security </a> </p>
<div align= "center" >

"Open the specified recordset article and sort by the date of the article, where there are two conditions, one is to use like to query the database and display the relevant article title, as well as to display the specified column by the returned typeID article
<%
Sql= "SELECT * from article where title like '%" &request ("Txtitle") & "% ' and typeid=" +cstr (typeid) + "ORDER by Date D Esc
Set rs= Server.CreateObject ("ADODB.") Recordset ")
Rs.Open sql,conn,1,1

"If the results of the query database point to the beginning or end of the recordset, there are no related articles in the database
If rs.eof and Rs.bof then
Response.Write "<p align= ' center ' > did not find any articles </p>"
Else
"If there is content in the database, get the number of articles in the database
Totalput=rs.recordcount
"If page parameter currentpage is less than 1, specify 1
If Currentpage<1 Then
Currentpage=1
End If
"Use the total number of articles and the maximum article count per page to count the pages of the score page
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 the page is 1 pages or the number of pages minus 1 times the maximum number of articles is less than the total number of articles, then use the already done function showpage in the Showcontent subroutine is the display of the title section of the article above and below display the paging program
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
The Define Bookmark
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
"Show article title and associated database content subroutine
Sub Showcontent
Dim i
I=0

%>
<div align= "center" ><center><table border= "1" cellspacing= "0" width= "589" bordercolorlight= "#000000" bordercolordark= "#FFFFFF" cellpadding= "0" >
<tr>
&LT;TD width= "align=" "Center" bgcolor= "#D0D0D0" height= "><strong>id" </strong></td>
&LT;TD width= "381" align= "center" bgcolor= "#D0D0D0" ><strong> article title </strong></td>
&LT;TD width= "align=" "Center" bgcolor= "#D0D0D0" ><strong> Add date </strong></td>
&LT;TD width= "align=" "Center" bgcolor= "#D0D0D0" ><strong> Click </strong></td>
</tr>
<%do While not rs.eof%>
<tr>
"In turn, the article ID number, article title, article add date and browse number, the openarticle.asp here is used to redirect the article, later will introduce
&LT;TD height= "width=" ><p align= "center" ><%=rs ("ArticleID")%></td>
&LT;TD width= "381" ><p align= "center" ><a href= "javascript:popwin2" (' Openarticle.asp?id=<%=rs () ArticleID ")%>&typeid=<%=cstr (typeid)%> ')" ><%=rs ("title")%></a></td>
&LT;TD width= "><p" align= "center" ><font color= "Red" ><i><%=rs ("date")%></i>< /font></td>
&LT;TD width= "><p" align= "Center" ><%=rs ("hits")%></td>
</tr>
<%
"Here is a loop, each show an article, the value of the variable i is defined plus one, when I's value is greater than or equal to the maximum number of articles on the page, exit the loop
I=i+1
If I>=maxperpage then Exit Do
"Automatically moves to the next record in the recordset after an article is displayed
Rs.movenext
Loop
%>
</table>
</center></div><%
End Sub

"Displays the page-splitting function
function ShowPage (totalnumber,maxperpage,filename)
Dim n

"Use the number of articles to calculate the pages of the article n
If Totalnumber mod maxperpage=0 then
n= totalnumber \ Maxperpage
Else
n= totalnumber \ Maxperpage+1
End If
Response.Write "<form method=post action=" &filename& "typeid=" &typeid& ">"
Response.Write "<p align= ' center ' ><font color= ' #000080 ' >>> pagination </font>"

"If the current number of pages is less than 2, the displayed article first and previous page does not show the connection, otherwise the current number of pages minus one to display the previous page, directly with page=1 to display the first
If Currentpage<2 Then
Response.Write "<font color= ' #000080 ' > Home prev </font>"
Else
Response.Write "<a href=" &filename& "page=1&typeid=" &typeid& "> Home </a>"
Response.Write "<a href=" &filename& "page=" &CurrentPage-1& "&typeid=" &typeid& "> Prev </a> "
End If

"If the paging page is less than 1, then the next and last page is displayed, otherwise the current number of pages plus one to display the next page, with the calculated article page number n show the end of the article
If N-currentpage<1 Then
Response.Write "<font color= ' #000080 ' > Next End </font>"
Else
Response.Write "<a href=" &filename& "page=" & (currentpage+1) & "&typeid=" &typeid& " > "
Response.Write "Next page </a> <a href=" &filename& "? page=" &n& "> End </a>"
End If

"Displays the number of pages and articles per page with N and Maxperpage
Response.Write "<font color= ' #000080 ' > page: </font><strong><font color=red>" &CurrentPage & "</font><font color= ' #000080 ' >/" &n& "</strong> page </font>"
Response.Write "<font color= ' #000080 ' > Total <b>" &totalnumber& "</b> article <b>" & maxperpage& "</b> article/Page </font>"

"Directly enter the page of the article to go to the relevant page
Response.Write "<font color= ' #000080 ' > Goto: </font><input type= ' text ' name= ' page ' size=4 maxlength=10 Class=smallinput value= "&currentpage&" > "
Response.Write "<input class=buttonface type= ' Submit ' value= ' Goto ' name= ' Cndok ' ></span></p></ Form> "
End Function
%>

"Article Search related programs
<form name= "Searchtitle" method= "POST" action= "index.asp" >

"The input of the query Word assignments value to txtitle, so in front of the display article has played a role in the title like '% ' &request (" Txtitle ") &"% "
<p> title: <input class= "Smallinput" type= "text" name= "Txtitle" size= "> <select class=" Smallsel "Name=" typeID "size=" 1 ">
<%

"Show the column information related to the article, you can select a query, and here the typeID also assigned to the typeID, so that the previous display of the program to show the content of the need to make a judgment
Typesql= "SELECT * from Type"
Rstype.open typesql,conn,1,1
Do as not rstype.eof
Sel= "Selected"
Response.Write "<option" & Sel & "Value=" +cstr (Rstype ("typeID")) + "' Name=typeid>" +rstype ("type") + " </option> "+CHR (10) +CHR
Rstype.movenext
Loop
Rstype.close
Set conn=nothing
%> </select><input class= "ButtonFace" type= "submit" value= "Query" name= "title" ></p>
</form>
</div></td>
</tr>
</table>
</center></div>
</body>

Here's an introduction to the program that opens the article openarticle.asp, which is also an update to the database content (update browsing number) and redirect files. Very simple, so here is a brief introduction to its program content:

<%@ language= "VBSCRIPT"%>
The Open database connection
<!--#include file= "conn.asp"-->
<%response.buffer=false
Dim sql
Dim rs
Dim ArticleID
"Update the number of browsing for the specified article with the article ID returned from the article connection using update, and the connection using the Response.Redirect redirect article
Articleid=request ("id")
Set Rs=server.createobject ("Adodb.recordset")
sql= "Update article set hits=hits+1 where articleid=" &articleid
Rs.Open sql,conn,1,1
Rs.close
Conn.close
Response.Redirect "List.asp?id=" &articleid
%>

OK, the article on the display of the first page is completed, it can display the title of the article, add dates and other articles related information, in addition, the article also combines the column search query function. Here you will find that the use of ASP to query the database is not a difficult thing, as long as the use of a like can be easily implemented, the article management of the foreground program we have basically completed, the following to introduce the management system of the background program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.