注册 登录
编程论坛 ASP技术论坛

if的一段代码,呵呵,初等的,解释一下,谢谢大家了

灯、、 发布于 2010-09-19 09:48, 841 次点击
我本来是学jsp的,因为临时要做个asp的网站后台,下面这段代码应该是VB之类的,我对VB只是大概了解,一些语法没学过,请大家给我解释一下,谢谢了

<!--#include file="inc/setup.asp" -->
<!--#include file="inc/CheckClass.inc.asp" -->
<!--#include file="dbconnect/news.inc.asp" -->

<%
on error resume next
dim pmcount,pageno

'//设置每页新闻数目
pmcount=news_front_count

dim rs,sql
set rs=server.createobject("adodb.recordset")

s_keyword = RtnReplaceString(trim(request("keyword")))
s_cataid = RtnReplaceInt(trim(request("cataid")),0)

sub getNewsBoardTree()
    set rsf=server.CreateObject("adodb.recordset")
    sqlf="Select * from newscata order by rootid"
    rsf.Open sqlf,conn,1,3
  
    do while not rsf.EOF
        tempcataStr="<option value='"&trim(rsf("id"))&"'"
        if trim(rsf("id")) = s_cataid then tempcataStr = tempcataStr&" selected"
            
        tempcataStr = tempcataStr&">"
        tempcataStr = tempcataStr&" | |"
            
        for i=1 to rsf("level")-1
            tempcataStr = tempcataStr&" |"
        next
            
        tempcataStr = tempcataStr&"_"&trim(rsf("title"))&"</option>"
        Response.Write tempcataStr
            
        rsf.MoveNext
        loop
        
      rsf.Close()
      set rsf=nothing
end sub
%>


这段代码放在HTML代码的上面
9 回复
#2
gupiao1752010-09-19 10:05
路过,帮顶!
#3
cnfarer2010-09-19 16:49
红色部分生成一个层次结构的下拉列表(并确定了当前的选中项)

[ 本帖最后由 cnfarer 于 2010-9-19 16:50 编辑 ]
#4
yms1232010-09-19 18:30
sqlf="Select * from newscata order by rootid"
选项是从newscata表读取出来的,按照rootid进行的排序
#5
灯、、2010-09-20 10:41
回复 3楼 cnfarer
我就是不太懂这几行代码啊,好像都是给tempcataStr一直在赋值吗,看着也不像sql语句,这种语法和C,java都不一样,所以看不懂,麻烦说下,呵呵
 tempcataStr = tempcataStr&" selected"
            
        tempcataStr = tempcataStr&">"
        tempcataStr = tempcataStr&" | |"
            
        for i=1 to rsf("level")-1
            tempcataStr = tempcataStr&" |"
#6
hams2010-09-20 10:53
相当于:
tempcataStr = tempcataStr&" selected"&">"&" | |"
            
        for i=1 to rsf("level")-1
            tempcataStr = tempcataStr&" |"
#7
cnfarer2010-09-20 11:18
回复 5楼 灯、、
&运算符是字符串连接
#8
灯、、2010-09-20 11:45
回复 6楼 hams
能用汉语解释下意思吗?里面是怎样运作的,真的谢谢
#9
hams2010-09-20 15:10
俺还没买螺丝刀,没办法打开里面。
#10
BeBass2010-09-20 17:19
<!--#include file="inc/setup.asp" -->   <!--引用asp文件-->
<!--#include file="inc/CheckClass.inc.asp" --> <!--这些文件里面可能声明了常量、方法等-->
<!--#include file="dbconnect/news.inc.asp" --> <!---->

<%
on error resume next '发生错误,继续运行,如果没有加上这个语句,当出现"运行时错误"时,会显示"出错信息"并停止程序的执行
dim pmcount,pageno

'//设置每页新闻数目
pmcount=news_front_count

dim rs,sql
set rs=server.createobject("adodb.recordset") '创建recordset对象,读取数据

s_keyword = RtnReplaceString(trim(request("keyword"))) 'request("keyword")读取请求数据,jsp里面也有吧
s_cataid = RtnReplaceInt(trim(request("cataid")),0)
            'RtnReplaceString()和RtnReplaceInt()以上include页面里面声明的方法
sub getNewsBoardTree() 'sub...end sub声明一个方法
    set rsf=server.CreateObject("adodb.recordset")
    sqlf="Select * from newscata order by rootid"
    rsf.Open sqlf,conn,1,3 '读取数据
      
        'do while ... loop 循环语句
    do while not rsf.EOF  '是否读取当最后一条数据,rsf.EOF到数据集末尾为true
        tempcataStr="<option value='"&trim(rsf("id"))&"'"    '构造下拉列表选项
        if trim(rsf("id")) = s_cataid then tempcataStr = tempcataStr&" selected"
                                rsf("id")   '读取id字段
        tempcataStr = tempcataStr&">"
        tempcataStr = tempcataStr&" | |"
            
        for i=1 to rsf("level")-1    '读取level字段
            tempcataStr = tempcataStr&" |"
        next
            
        tempcataStr = tempcataStr&"_"&trim(rsf("title"))&"</option>"  '读取title字段
        Response.Write tempcataStr
            
        rsf.MoveNext  '数据集rsf移动到下一条
     loop
        
      rsf.Close()  '关闭数据集
      set rsf=nothing  '回收资源
end sub
%>
1