欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

asp数据库循环输出 有大用

asp数据库循环输出

dim rs,sql,NavName
set rs = server.createobject("adodb.recordset")
sql="select * from Navigation where ViewFlag order by Sequence asc"
rs.open sql,conn,1,1
if rs.bof and rs.eof then
response.write "暂无导航"
else
do while not rs.eof
NavName = rs("NavName")
rs.movenext
loop
end if
rs.close
set rs=nothing

if IsArray(NavName) then
response.write "是数组"
else
response.write "不是数组"
end if

怎么把NavName 定义成数组函数
在就是 怎么把NavName
拿出来循环输出 不在do while里
 我来答  举报
匿名用户
2013-09-13
'呵,何必这么复杂,如果要输出与数组相关的话,不要忘了asp里有个很好用的rs.GetRows()了,给你段最简单的代码吧,如下:dim rs,arr,iset rs=conn.execute("select * from Navigation where ViewFlag order by Sequence asc")if not rs.eof then arr=rs.GetRows() '这里把符合条件的所有记录都保存到了arr中,这里赋值后的arr就等于是一个二维数组了end if
rs.closeset rs=nothing'上面代码就完成了从数据库读取数据到数组变量了,接下来只要输出数据,你只需要判断arr是否数组if isarray(arr) then for i=0 to ubound(arr,2) '上面有仁兄说过数组长度由ubound下标决定没错,所以你只要确定第二维的下标就知道数组长度ubound(arr,2),当然第一维就是ubound(arr,1)或者ubound(arr)就行了 response.write arr(0,i) '这里就是输出数组item了 response.write "<br>" '每输出一个数据就换一行,当然你也可以改成别的 nextelse response.write "暂无导航"end if '搞定
匿名用户
2013-09-13
rs("NavName") 本身就是数组 , 如果为了输出的话, 没必要再放置到另外数组中, 一般的循环使用for=====......
if rs.bof and rs.eof then
response.write "暂无导航"
else
for i=0 to rs.recordcountrespone.write rs("NavName") rs.movenextnext


来自 https://zhidao.baidu.com/question/559364130171193844.html


普通分类: