Sql="Select top 10 * From [Dv_Topic] Order By TopicID DESC,boardid DESC"
这样就可以了,优先TopicID倒序再按boardid倒序,你试试!
按id号从小到大排列sql = "select * from tablename order by id asc"
按id号从大到小排列
sql = "select * from tablename order by id desc"
举例如下:
下面是一段正常的源码,它可以正常查询出倒序结果:
<!--#include file="conn.asp" -->
<head>
<title>回眸一笑</title>
<style><!--@import url(in/index.css)--></style>
<style><!--@import url(in/layer.css)body,td,th {
font-family: 宋体
color: #000
}
--></style>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312"></head>
<body text="#000000" >
<div id="newest">
<div id="ntitle" align="right">最新10篇帖子:</div>
<div id="space"></div>
<div id="nmarquee">
<table width="100%" height="12" border="0" cellpadding="0" cellspacing="0">
<tr>
<td id=demo1>
<table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<%
Dim nSql
nSql="Select top 10 * From [Dv_Topic] Order By TopicID DESC"
Dim nRs
Set nRs=Server.CreateObject("ADODB.RecordSet")
nRs.Open nSql,Conn1,1,1
while not nRs.eof
%>
<td height="17"><table width="500"><tr><td width="492" height="10">
<a href='../../xiabbs/Dvbbs8.2.0_Ac/dispbbs.asp?TopicIDid=<%=nRs("TopicID")%>'>
<strong><font color="#333366"><%=left(nRs("PostUserName"),5)%></font></strong>
<font color="#FF3366">发贴于 </font>
<strong><font color="#333366"><%=left(nRs("DateAndTime"),12)%></font></strong>:<%=left(nRs("Title"),20)%>
</a></td></tr></table></td>
<%
nRs.movenext
wend
nRs.close:set nRs = nothing
%>
但是把它的链接更改,使它指向其它ID,但查询结果却顺序显示了。代码如下:
<!--#include file="conn.asp" -->
<head>
<title>回眸一笑</title>
<style><!--@import url(in/index.css)--></style>
<style><!--@import url(in/layer.css)body,td,th {
font-family: 宋体
color: #000
}
--></style>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312"></head>
<body text="#000000" >
<div id="newest">
<div id="ntitle" align="right">最新10篇帖子:</div>
<div id="space"></div>
<div id="nmarquee">
<table width="100%" height="12" border="0" cellpadding="0" cellspacing="0">
<tr>
<td id=demo1>
<table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<%
Dim nSql
nSql="Select top 10 * From [Dv_Topic] Order By TopicID DESC"
nSql="Select top 10 * From [Dv_Topic] Order By boardid DESC"<!--这里添加了查询表,以为下面链接提供ID链接-->
Dim nRs
Set nRs=Server.CreateObject("ADODB.RecordSet")
nRs.Open nSql,Conn1,1,1
while not nRs.eof
%>
<td height="17"><table width="500"><tr><td width="492" height="10">
<!--下面的链接添加了boardid以便动态链接。-->
<a href='../../xiabbs/Dvbbs8.2.0_Ac/dispbbs.asp?boardid=<%=nRs("boardid")%>&id=<%=nRs("TopicID")%>'>
<strong><font color="#333366"><%=left(nRs("PostUserName"),5)%></font></strong>
<font color="#FF3366">发贴于 </font>
<strong><font color="#333366"><%=left(nRs("DateAndTime"),12)%></font></strong>:<%=left(nRs("Title"),20)%>
</a></td></tr></table></td>
<%
nRs.movenext
wend
nRs.close:set nRs = nothing
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)