asp实现内容页上一篇和下一篇功能
这一段代码你看看吧! 我的表名为newslist,n_id是表里的字段名类似你的id号,n_pid是类别字段。如果是同一个类别的文章的话,n_pid值是相同的! 以下代码应该很容易看懂的! <td width="50%" height="35" align="left" style="padding-left:15px "> 上一条: <% n_id=request("id") Set rs3=Server.CreateObject("Adodb.RecordSet") rs3.Open "Select top 1 * from newslist where n_pid=107 and n_id<"&n_id&" order by n_id desc",conn,1,1 IF not rs3.eof and not rs3.bof Then response.write"<a href='?id="&rs3("n_id")&"'>"&rs3("n_title")&"</a>" else response.write"没有上一个了" end if %> </td> <td width="50%" align="right"> 下一条: <%Set rs2=Server.CreateObject("Adodb.RecordSet") rs2.Open "Select top 1 * from newslist where n_pid=107 and n_id>"&n_id&" order by n_id asc",conn,1,1 IF not rs2.eof and not rs2.bof Then response.write" <a href='?id="&rs2("n_id")&"'>"&rs2("n_title")&"</a>" else response.write" 没有下一个了" end if %> </td>
来源:展洋科技 www.35544216.com
|