當前位置:編程學習大全網 - 源碼下載 - 怎麽讓網頁讀取數據庫後倒序顯示

怎麽讓網頁讀取數據庫後倒序顯示

按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/html; charset=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/html; charset=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

%>

  • 上一篇:發朋友圈讓人秒贊的文案
  • 下一篇:openfire配置 成功後重啟就出現這中錯誤,各位大神求解
  • copyright 2024編程學習大全網