ASP循环输出

来源:百度知道 编辑:UC知道 时间:2024/06/02 06:51:13
程序目的:动态生成静态页面,在后台生成

'开始执行
Sub Morecity()

htmlName="morecity.html" '静态文件名称

Content=CreateHeader() '调用函数

response.write Content
response.end()
'为什么在这里输出时只有最后一个省份的值?而其它的没有输出
End Sub

Function CreateHeader()
set rs=conn.execute("select * from province") '省份表不只一个值
i=1
do while not rs.eof
str=" <div id=main_1>"
str=str&" <div id=main_left>"&rs("ProvinceName")&" </div>"
str=str&" <div id=main_right>"
set rsc=conn.execute("select * from city where pid="&rs("id")&"")
do while not rsc.eof
str=str&" <a href=city.asp?id="&rsc("cityid")&"> <span class=city_size>"
if rsc("rec")="y" then
str=str&" <font color=#ff0000>"

do while not rs.eof
str=" <div id=main_1>"
你在这里再次循环的时候把STR的值重置了.你把这里改成
do while not rs.eof
str= str & " <div id=main_1>"
就行了,再在返回值后把它重置为空.

因为数据集rs的指针直接指向了最后一个数据。把指针移到最前面!

```````````
Function CreateHeader()
set rs=conn.execute("select * from province") '省份表不只一个值
i=1
rs.movefirst '把指针移到数据集rs的最前面!
do while not rs.eof
str=" <div id=main_1>"
str=str&" <div id=main_left>"&rs("ProvinceName")&" </div>"
str=str&" <div id=main_right>"
set rsc=conn.execute("select * from city where pid="&rs("id")&"")
do while not rsc.eof
str=str&" <a href=city.asp?id="&rsc("cityid")&"> <span class=city_size>"
if rsc("rec")="y" then

```````````
移动一下位置试试