注册 登录
编程论坛 WEB前端(UI)

求中段代码的详细说明

adweset 发布于 2009-08-31 01:50, 774 次点击
sql="select * from SoftDown_SoftInfo where SoftID="&SoftID
 rs.open sql,conn,1,1
 DayDate=trim(rs("DayDate"))
 WeekDate=trim(rs("WeekDate"))
 MonthDate=trim(rs("MonthDate"))
 AllHits=trim(rs("AllHits"))
 avgGrade=trim(rs("avgGrade"))
 Points=rs("Points")
 '更新软件下载次数
 sql="update SoftDown_SoftLink set Hits=Hits+1 where Id=" & cstr(request.QueryString("ID"))
 conn.execute sql
 sql="update SoftDown_SoftInfo set AllHits=AllHits+1,DayHits=DayHits+1,WeekHits=WeekHits+1,MonthHits=Monthhits+1 where SoftId=" & SoftID
 conn.execute sql

 if datediff("H",DayDate,Now)>=24 then
 sql="update SoftDown_SoftInfo set DayDate=Now(),DayHits=1 where SoftId=" & SoftID
 conn.execute sql      
 end if

 if datediff("D",WeekDate,Now)>=7 then
 sql="update SoftDown_SoftInfo set WeekDate=Now(),WeekHits=1 where SoftId=" & SoftID
 conn.execute sql
 end if

 if datediff("D",MonthDate,Now)>=31 then
 sql="update SoftDown_SoftInfo set MonthDate=Now(),MonthHits=1 where SoftId=" & SoftID
    conn.execute sql
 end if

 rs.close
1 回复
#2
gupiao1752010-03-31 17:33
sql="select * from SoftDown_SoftInfo where SoftID="&SoftID //在数据库表SoftDown_SoftInfo中查询字段SoftID=变量SoftID的所有相关数据。
rs.open sql,conn,1,1 //以只读方式打开该数据表
DayDate=trim(rs("DayDate")) //取得数据库SoftDown_SoftInfo表里DayDate字段的值并将其两边空格去除后存入变量DayDate里,trim是ASP自带函数,下同!
WeekDate=trim(rs("WeekDate")) //取得数据库SoftDown_SoftInfo表里WeekDate字段的值并将其两边空格去除后存入变量WeekDate里,下同!
MonthDate=trim(rs("MonthDate")) 同上
AllHits=trim(rs("AllHits")) 同上
avgGrade=trim(rs("avgGrade")) 同上
Points=rs("Points") 同上,区别就是没用trim函数
'更新软件下载次数
sql="update SoftDown_SoftLink set Hits=Hits+1 where Id=" & cstr(request.QueryString("ID")) //根据SoftDown_SoftLink表里的ID值更新Hits字段(使其加1)
conn.execute sql //执行数据库操作代码(也就是上面的代码)
sql="update SoftDown_SoftInfo set AllHits=AllHits+1,DayHits=DayHits+1,WeekHits=WeekHits+1,MonthHits=Monthhits+1 where SoftId=" & SoftID
conn.execute sql //根据SoftDown_SoftLink表里的SoftID值更新AllHits、DayHits、WeekHits、MonthHits等4个字段(都使其加1)

if datediff("H",DayDate,Now)>=24 then //将DayDate和Now两个变量的时间进行比较,取得小时值,如果大于等于24则执行下面的代码,否则直接跳出该IF语句,执行下一个IF。关于DATEDIFF函数可以自己上百度上找,也是自带函数!
sql="update SoftDown_SoftInfo set DayDate=Now(),DayHits=1 where SoftId=" & SoftID
conn.execute sql      
end if

if datediff("D",WeekDate,Now)>=7 then//将WeekDate和Now两个变量的时间进行比较,取得星期值,如果大于等于7则执行下面的代码,否则直接跳出该IF语句,执行下一个IF。
sql="update SoftDown_SoftInfo set WeekDate=Now(),WeekHits=1 where SoftId=" & SoftID
conn.execute sql
end if

if datediff("D",MonthDate,Now)>=31 then //将MonthDate和Now两个变量的时间进行比较,取得日期值,如果大于等于31则执行下面的代码,否则直接跳出该IF语句,执行下一个IF。
sql="update SoftDown_SoftInfo set MonthDate=Now(),MonthHits=1 where SoftId=" & SoftID
    conn.execute sql
end if

rs.close //关闭数据库!
1