Use the next article in the record in the database (iii)

Source: Internet
Author: User
Tags prev access
Iii. Examples of bookmark/movenext/moveprevious

Let's look at an example of an ASP code that uses Bookmark/movenext/moveprevious to do the next function in the previous article.

For example, ASP code rs15.asp as follows:

<%

Set conn1 = Server.CreateObject ("ADODB. Connection ")

Conn1. Open "dbq=" & Server.MapPath ("Ntopsamp.mdb") & ";D river={microsoft Access Driver (*.mdb)};D riverid=25;fil=ms Access; "

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

SQLSTR = "SELECT * from"

Rs2. Open sqlstr,conn1,1,1

Bkstart = rs2. Bookmark

Bkend = rs2. Bookmark + rs2. RecordCount-1

Rs2. MoveNext

If Request ("sel") = "Prev" Then

Rs2. Bookmark = Session ("Bookmark")

Rs2. MovePrevious

ElseIf Request ("sel") = "Next" Then

Rs2. Bookmark = Session ("Bookmark")

Rs2. MoveNext

End If

Session ("Bookmark") = rs2. Bookmark

%>

<table colspan=8 cellpadding=5 border=0>

<TR>

&LT;TD align=center bgcolor= "#008080" ><font color= "#FFFFFF" > title </FONT></TD>

&LT;TD align=center bgcolor= "#008080" ><font color= "#FFFFFF" > Publishing </FONT></TD>

&LT;TD align=center bgcolor= "#008080" ><font color= "#FFFFFF" > Pictures </FONT></TD>

&LT;TD align=center bgcolor= "#008080" ><font color= "#FFFFFF" > Introduction </FONT></TD>

<TR>

&LT;TD bgcolor= "F7efde" align=center><%= rs2 ("title")%></td>

&LT;TD bgcolor= "F7efde" align=center><%= rs2 ("published")%></td>

&LT;TD bgcolor= "F7efde" align=center><%= rs2 ("picture")%></td>

&LT;TD bgcolor= "F7efde" align=center><%= rs2 ("Introduction")%></td>

</TR>

</TABLE>

<% = Session ("Bookmark")%>

<% if session ("Bookmark") > Bkstart then%>

<a href=rs15.asp?sel=prev> on a piece of </A>

<% End If%>

<% if session ("Bookmark") < Bkend then%>

<a href=rs15.asp?sel=next> Next </A>

<% End If%>

<% rs2. Close%>

The above ASP code rs15.asp, uses the browser in the client side, browses the execution result, displays the previous article the function.

The bookmark (bookmark) Position of the user's recordset is stored by the session ("bookmark"), and when the [previous] super connection is pressed, the <a href=rs15.asp?sel=prev> the previous one </a The SEL is set to Prev and the rs15.asp ASP code is executed again. The following program section first sets the Bookmark property to the name of the set bookmark ("Bookmark"), returns to the location of the last bookmark, and then uses MovePrevious to move to the previous position:

If Request ("sel") = "Prev" Then

Rs2. Bookmark = Session ("Bookmark")

Rs2. MovePrevious

ElseIf Request ("sel") = "Next" Then

Rs2. Bookmark = Session ("Bookmark")

Rs2. MoveNext

End If

Session ("Bookmark") = rs2. Bookmark

Then use the session ("Bookmark") = rs2. The bookmark is set, and the session ("bookmark") stores the name of the bookmark mark.

When the [next] super connection is pressed, the <a href=rs15.asp?sel=next> the next </a&gt, sets the sel to next, and executes the rs15.asp ASP code again. From the above program section, return to the location of the last bookmark, and then use MoveNext to move to the next position.

The position of the bookmark is displayed by <% = Session ("Bookmark")%> Note that the position of the first record is not 0 but 1792, so we have to get the bookmark position value of the first and the end to determine whether to display the [previous] [next] super connection.

In order to determine whether to display [previous] [next] super connection, by the following program part, we set two bookmarks, by Bkstart = rs2. Bookmark sets the position of the first article by Bkend = Rs2. Bookmark + rs2. RecordCount-1 set the position of the end bar:

<%

SQLSTR = "SELECT * from"

Rs2. Open sqlstr,conn1,1,1

Bkstart = rs2. Bookmark

Bkend = rs2. Bookmark + rs2. RecordCount-1

If session ("Bookmark") > Bkstart then%>

<a href=rs15.asp?sel=prev> on a piece of </A>

<% End If%>

<% if session ("Bookmark") < Bkend then%>

<a href=rs15.asp?sel=next> Next </A>

<% End If%>

You can use the IF session ("bookmark") > Bkstart, the If session ("bookmark") < Bkend to compare the current position session ("bookmark") and the first Bkstart, The end of the Bkend position to determine if you want to display a hyperlink to [previous] [next].


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.