日期:2014-05-17  浏览次数:21022 次

这是一篇有关新闻文章中上一篇下一篇的代码,想修改为按时间排序如何做(只在修改SQL排序是不行的,排出的顺序不对)?
<%
dim pid1,pid2,pid3
classid = rs3("Smallclassid")
pid1=rs3("newsid")
function Getpre
sql="select top 1 * from news where newsid >"&pid1&" and SmallClassID="&classid&" order by newsid asc"
set rs3=conn.execute(sql)
if rs3.eof or rs3.bof then
response.Write("没有新闻了")
else
pid2=rs3("newsid")
response.Write("<a href='default.asp?newsid="&pid2&"'>"&rs3("title")&"</a>")
end if
end function

function Getnext
sql="select top 1 * from news where newsid <"&pid1&" and SmallClassID="&classid&" order by newsid desc"
set rs3=conn.execute(sql)
if rs3.eof then
response.Write("没有新闻了")
else
pid3=rs3("newsid")
response.Write("<a href='default.asp?newsid="&pid3&"'>"&rs3("title")&"</a>")
end if
end function
%>
<table width="438" border="0" cellpadding="0" cellspacing="0">
  <tr>
  <td width="399"><span class="shang">上一篇:
  <% getpre %>
  </span></td>
  </tr>
  <tr>
  <td><span class="shang">下一篇:
  <% getnext %>
  </span></td>
  </tr>
</table>

------解决方案--------------------
VBScript code
dim pid1,pid2,pid3
classid = rs3("Smallclassid")
pid1=rs3("newsid")

shijian=rs3("时间字段")'============

function Getpre
sql="select top 1 * from news where 时间字段 >'"&shijian&"' and SmallClassID="&classid&" order by newsid asc"'============
set rs3=conn.execute(sql)
if rs3.eof or rs3.bof then
response.Write("没有新闻了")
else
pid2=rs3("newsid")
response.Write("<a href='default.asp?newsid="&pid2&"'>"&rs3("title")&"</a>")
end if
end function

function Getnext
sql="select top 1 * from news where 时间字段 <'"&shijian&"' and SmallClassID="&classid&" order by newsid desc"'============
set rs3=conn.execute(sql)
if rs3.eof then
response.Write("没有新闻了")
else
pid3=rs3("newsid")
response.Write("<a href='default.asp?newsid="&pid3&"'>"&rs3("title")&"</a>")
end if
end function