asp中for循环排序问题

来源:百度知道 编辑:UC知道 时间:2024/09/20 12:15:07
在asp中从数据库里面提取出数据,放到数组t(11)里面,然后排序,程序源代码如下:
<%
dim db,conn,myconn,tt,i,j
Dim t(11)
db="bat/dat.mdb"
Set Conn = Server.CreateObject("ADODB.Connection")
myconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
Conn.Open MyConn

set rs=server.createobject("adodb.recordset")
for id =1 to 12
sql=("select * from 表1 where id="&id&"")
rs.open sql,conn,3,3
t(id-1)=rs("cishu")
rs.update
rs.close
next

for i=0 to 10
for j=0 to 10-i
if t(j)>t(j+1) then
tt=t(j+1)
t(j+1)=t(j)
t(j)=tt
end if
next
next

%>
提取出的数据为:342 123 343 6 5 33 78 56 32 1 28 31
运行后的结果为:78 6 56 5 343 342 33 32 31 28 123 1
很明显他只对第一位数排序,请问怎样改采能正确排序呢???

没必要这么繁的,直接在查询数据库的时候排序就得了:

<%
set rs=server.createobject("adodb.recordset")
sql="select * from 表1 where id>=1 and id<=12 order by cishu"
rs.open sql,conn,1,1
' 查询出来的rs中cishu已经排序了
'下面把记录集放入t数组中
i=0
do while not rs.eof
t(i)=rs("cishu")
rs.MoveNext
i=i+1
loop
rs.close
%>