Previous and next articles asp, php, asp.net, jsp, etc.

Source: Internet
Author: User
Tags prev

The core SQL statements of the previous article and the next article are as follows:

Previous

The code is as follows: Copy code
Select top 1 Id from [table] where Id <@ current ID order by Id desc

Next Article

The code is as follows: Copy code
Select top 1 Id from [table] where Id> @ current ID order by Id

In the future, no matter how asp php jsp asp.net is implemented, we will introduce asp and php practices.

Add the following code to the news. asp file:

The code is as follows: Copy code

<%
Set backrsd = server. CreateObject ("Adodb. recordset ")
SQL = "select top 1 * from news where id <" & id & "order by id desc"
Set backrsd=conn.exe cute (SQL)
If backrsd. eof then
NewTitle4 = "already the first article"
Else
Id2 = backrsd ("id ")
NewTitle2 = backrsd ("title ")
End If
Backrsd. close

Set nextrsd = server. CreateObject ("adodb. recordset ")
SQL = "select top 1 * from news where id>" & id & "order by id"
Set nextrsd=conn.exe cute (SQL)
If nextrsd. eof then

NewTitle3 = "this is the last article"
Else
Id1 = nextrsd ("id ")
NewTitle1 = nextrsd ("title ")
End If
Nextrsd. close
%>

 

Add the following code to <body>:

The code is as follows: Copy code
<Br> previous article: <% = NewTitle4 %> <a href = 'news. asp? Newid = <% = id2 %> '> <% = NewTitle2 %> </a>
<Br> next article: <% = NewTitle3 %> <a href = 'news. asp? Newid = <% = id1 %> '> <% = NewTitle1 %> </a>


Php Usage

The code is as follows: Copy code

Function nextpage ($ fid, $ tag, $ bid ){
If ('next' = $ tag ){
$ SQL = "select * from gx_news where id <$ fid and menu_id = '$ bid' order by id desc ";
} Elseif ('prev' ==$ tag ){
$ SQL = "select * from gx_news where id> $ fid and menu_id = '$ bid' order by id asc ";
  }
$ Result = mysql_query ($ SQL );
If (! Mysql_num_rows ($ result )){
Echo ('No more! ');
} Else {
$ Rs = mysql_fetch_array ($ result );
Echo "<a href = news_page.php? Id = ". $ rs [0]."> ". $ rs ['new _ title']." </a> ";
  }
 }


Call

The code is as follows: Copy code
Nextpage ($ fid, 'next', $ bid); next page
Nextpage ($ fid, 'prev', $ bid); Previous Page


Well, I am talking about only two ways to implement the previous and next implementations of all programming languages.

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.