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

新手问问每天都清空的那个数据是怎么实现的?

唯入进来 发布于 2010-05-30 19:56, 846 次点击
我有个网站,数据库里面有个数据值是每天准时清空为零值的,我想改回一个星期才清一次,请问是通过什么代码实现的,还是在数据库设置的?
下面应该就是代码的地方
程序代码:
<%
Function ShowTop(x,y)
Dim OutStr,conditionstr
Dim rs,sql,i
if y=2 then
if x=1 then
conditionstr
=" where inc>0 order by inc desc"
else
conditionstr
=" where outc>0 order by outc desc"
'conditionstr=" where 1=1 order by dateandtime desc"
end if
sql
="select top 10 sitename,inc,outc,username from 09Qzone_Cn_Link "&conditionstr
else
if x=1 then
conditionstr
=" where inj>0 order by inj desc"
else
conditionstr
=" where outj>0 order by outj desc"
end if
sql
="select top 10 sitename,inj,outj,username from 09Qzone_Cn_Link "&conditionstr
end if
OutStr
= "<table cellpadding=1 cellspacing=0 border=0 class=nav>"
set rs=hx.Execute(sql)
if rs.eof then
OutStr
= OutStr & "<tr><td align=center>暂时还没有数据</td></tr>"
else
do while not rs.eof and i<10
OutStr
= OutStr & "<tr><td width=115>"
OutStr
= OutStr & "&nbsp;<img src=images/star520.gif>"
OutStr
= OutStr & " <a target=_blank href=out.asp?username="&rs(3)&">"&rs(0)&"</a>"
OutStr
= OutStr & "</td><td width=50 align=right><font color=#99FF00>"
if x=1 then
OutStr
= OutStr & ""&rs(1) & ":票"
else
OutStr
= OutStr & ""&rs(2) & ":次"
end if
OutStr
= OutStr & "</span></font></font></td><tr>"
i
=i+1
rs.movenext
loop
end if
OutStr
= OutStr & "</table>"
Response.Write OutStr
End Function
%>

inj,outj,这两个就是每天都会清一次的,不知道这里代码全不全。

[ 本帖最后由 唯入进来 于 2010-5-30 19:59 编辑 ]
8 回复
#2
gupiao1752010-05-30 20:59
你的数据库是什么?

这里的代码不全,要实现那个效果,如果用SQL最起码也要有个UPDATE语句!可是你的代码里并没有!

如果你把所有代码都看了一遍没有找到UPDATE inj/outj相关的语句,那么这2个字段估计就是在数据库由SQL SERVER的处发器过程或ACCESS里的宏进行自动处理的!
#3
唯入进来2010-05-30 21:08
access的
#4
唯入进来2010-05-30 21:23
宏怎么看,我好像在软件的宏菜单里没看到什么东西,是不是asp也会有update这个
#5
唯入进来2010-05-30 21:46
程序代码:
<%

class cls_8808qq_cn
   
Public BaseUrl
   
Public WebName,WebUrl,SysName,SysNameE,SysVersion,ip
   
Public rs
   
Private Sub Class_Initialize()
        BaseUrl
= LCase(Replace(Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL"),Split(request.ServerVariables("SCRIPT_NAME"),"/")(ubound(Split(request.ServerVariables("SCRIPT_NAME"),"/"))),""))
        ip
=checkstr(request.ServerVariables("REMOTE_ADDR"),15)

        
'初始化当天数据
        if application("CL_Date")<>Date() then
            init_data
        
end if
   
End Sub
   
Private Sub class_terminate()
        
If IsObject(Conn) Then
            Conn.Close
            
Set Conn = Nothing
        
End If
   
End Sub

   
Public Function Execute(Command)
        
If Not IsObject(Conn) Then ConnectionDatabase   
        
On Error Resume Next
        
Set Execute = Conn.Execute(Command)
        
If Err Then
            
If IsDeBug = 1 Then
                Response.Write
"你执行的语句是:" & Command
                Response.Write
"<BR>错误信息为:" & Err.description
            
Else
                Response.Write
"查询数据的时候发现错误,请检查您的查询代码是否正确。"
            
End If
            Err.Clear
            CloseDatabase
            Response.End
        
End If   
   
End Function

   
Public Function Checkstr(Str,length)
        
If Isnull(Str) Then
            CheckStr
= ""
            
Exit Function
        
End If
            CheckStr
= trim(Replace(Str,"'","''"))
        
if instr(Str,"%27") then
            CheckStr
= trim(Replace(Str,"%27","''"))
        
End if        
        
if length>0 and strlength(CheckStr)>length then
                CheckStr
=Strleft(CheckStr,length)
        
End if
   
End Function


   
Public Function htmlencode2(str)
        htmlencode2
=Server.Htmlencode(str)
        htmlencode2
=replace(htmlencode2,chr(10),"&nbsp;")
        htmlencode2
=replace(htmlencode2,chr(13),"&nbsp;")
        htmlencode2
=replace(htmlencode2,chr(32),"&nbsp;")
   
End Function
   
   
Public Function Strlength(Str)
        
dim Temp_Str,I,Test_Str
        Temp_Str
=Len(Str)
        
For I=1 To Temp_Str
            Test_Str
=(Mid(Str,I,1))
            
If Asc(Test_Str)>0 Then
                Strlength
=Strlength+1
            
Else
                Strlength
=Strlength+2
            
End If
        
Next
   
End Function
   
   
Public Function Strleft(Str,L)
        
dim Temp_Str,I,lens,Test_Str
        Temp_Str
=Len(Str)
        
For I=1 To Temp_Str
            Test_Str
=(Mid(Str,I,1))
            Strleft
=Strleft&Test_Str
            
If Asc(Test_Str)>0 Then
                lens
=lens+1
            
Else
                lens
=lens+2
            
End If
               
If lens>=L Then Exit For
        
Next
   
End Function

   
Public Function isInteger(para)
        
on error resume next
        
dim str
        
dim l,i
        
if isNUll(para) then
            isInteger
=false
            
exit function
        
End if
        str
=cstr(para)
        
if trim(str)="" then
            isInteger
=false
            
exit function
        
End if
        l
=len(str)
        
for i=1 to l
        
if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
            isInteger
=false
            
exit function
            
End if
        
next
        isInteger
=true
        
if err.number<>0 then err.clear
   
End Function

   
Public Function showwebtype(id)
        
dim rs
        
set rs=execute("select name from 09Qzone_Cn_WebType where id="&id)
        
if rs.eof then
            showwebtype
="其它"
        
else
            showwebtype
=rs(0)
        
End if
        
set rs=nothing
   
End Function


   
   
Public Sub write_log(num)
        
Execute("insert into 09Qzone_Cn_Log (username,ip,inout) values('"&username&"','"&ip&"',"&num&")")
   
End Sub
   
   
Public Function isrec(num)
        
dim rs
        
set rs=execute("select top 1 dateandtime from 09Qzone_Cn_Log where ip='"&ip&"' and username='"&username&"' and inout="&num&" order by id desc")
        
if rs.eof then
            
Call write_log(num)
            isrec
=false
        
elseif DateDiff("h",rs(0),now())>HitsTime then
            
Call write_log(num)
            isrec
=false
        
else
            isrec
=true               
        
end if
   
End Function
   
   
Public Sub init_data
        
dim sql   
        
set rs=Server.CreateObject("ADODB.RecordSet")
        sql
="select outc,outj,fromdate,inc,inj,indate from 09Qzone_Cn_Link order by indate desc"
        rs.open sql,conn,
1,2
        
do while not rs.eof
If DateDiff("d",rs("indate"),Date())<>0 then               
rs(
"inj")=0
rs(
"outj")=0
End If
            rs.update
            rs.movenext
        
loop
        rs.close
        
set rs = nothing
        application(
"CL_Date")=date()
   
End Sub

   
'以下是严格判断
    Public Function blnfilter(str)
        
if FilterWordQq <> "" then
        
dim arrfilter,j
        arrfilter
= split(FilterWordQq,"|")
        
for j = 0 to ubound(arrfilter)
        
if StrComp(str,arrfilter(j),0) =0 then
            blnfilter
= true
            
Exit Function
        
end if
        
next
        
end if
        blnfilter
= false
   
End Function


   
Public Function blnfilter1(str)
        
if FilterWordText <> "" then
        
dim arrfilter,j
        arrfilter
= split(FilterWordText,"|")
        
for j = 0 to ubound(arrfilter)
        
if instr(str,arrfilter(j))>0 then
            blnfilter1
= true
            
Exit Function
        
end if
        
next
        
end if
        blnfilter1
= false
   
End Function   
   
End class

Class Cls_Cache
   
Public Reloadtime,CacheName
   
Private LocalCacheName,CacheData,DelCount
   
Private Sub Class_Initialize()
        Reloadtime
=14400
        CacheName
="hx"
   
End Sub
   
Private Sub SetCache(SetName,NewValue)
        Application.Lock
        Application(SetName)
= NewValue
        Application.unLock
   
End Sub
   
Private Sub makeEmpty(SetName)
        Application.Lock
        Application(SetName)
= Empty
        Application.unLock
   
End Sub
   
Public  Property Let Name(ByVal vNewValue)
        LocalCacheName
=LCase(vNewValue)
   
End Property
   
Public  Property Let Value(ByVal vNewValue)
        
If LocalCacheName<>"" Then
            CacheData
=Application(CacheName&"_"&LocalCacheName)
            
If IsArray(CacheData)  Then
                CacheData(
0)=vNewValue
                CacheData(
1)=Now()
            
Else
               
ReDim CacheData(2)
                CacheData(
0)=vNewValue
                CacheData(
1)=Now()
            
End If
            SetCache CacheName
&"_"&LocalCacheName,CacheData
        
Else
            Err.Raise vbObjectError
+ 1, "hxCacheServer", " please change the CacheName."
        
End If        
   
End Property
   
Public Property Get Value()
        
If LocalCacheName<>"" Then
            CacheData
=Application(CacheName&"_"&LocalCacheName)   
            
If IsArray(CacheData) Then
                Value
=CacheData(0)
            
Else
                Err.Raise vbObjectError
+ 1, "hxCacheServer", " The CacheData Is Empty."
            
End If
        
Else
            Err.Raise vbObjectError
+ 1, "hxCacheServer", " please change the CacheName."
        
End If
   
End Property
   
Public Function ObjIsEmpty()
        ObjIsEmpty
=True
        CacheData
=Application(CacheName&"_"&LocalCacheName)
        
If Not IsArray(CacheData) Then Exit Function
        
If Not IsDate(CacheData(1)) Then Exit Function
        
If DateDiff("s",CDate(CacheData(1)),Now()) < 60*Reloadtime  Then
            ObjIsEmpty
=False
        
End If
   
End Function
   
Public Sub DelCahe(MyCaheName)
        makeEmpty(CacheName
&"_"&MyCaheName)
   
End Sub

   
End Class
%>



肯定是这个文件了
If DateDiff("d",rs("indate"),Date())<>0 then               
rs("inj")=0
rs("outj")=0
End If

帮忙看看怎样把每天清零一次改为每周清零一次,
文件超过字节限制,删了一些没相关的代码。

还有一个我的网站放在美国的空间上,由于时区差关系,本来应该凌晨零点清零的数据,结果在中间变成了下午三点才清零了,有办法让它在中国的凌晨零点清零吗?

[ 本帖最后由 唯入进来 于 2010-5-30 23:24 编辑 ]
#6
hams2010-05-31 09:59
If DateDiff("d",rs("indate"),Date())<>6 then   
#7
gupiao1752010-05-31 10:35
美国时间比较复杂,还看你的服务器在西区还是东区。
一般在说中美时差时,都是说北京时间和美国东部时间或西部时间的时差。而美国又实行夏时制,美国实行夏时制时,北京时间比美国东部(简称为E.T.)时间正好早12个小时。非夏时制时,北京时间比美国东部时间早13个小时,夏时制时,如果你按13小时算,误差还会产生一个小时!如果不考虑夏时制的这一个小时,那么:北京时间=美国时间+13个小时,那么你WEB代码的时间必须设置为:应该把hour()+13来处理,具体情况你新建一个最简单的ASP测试页面测试一下!

#8
唯入进来2010-05-31 14:36
以下是引用hams在2010-5-31 09:59:34的发言:

If DateDiff("d",rs("indate"),Date())<>6 then   


<>6 就代表服务器时间的每周星期天凌晨一点清零数据吗?


服务器时间和北京时间应该是相差十五个小时,我这里是下午三点清零数据。
#9
hams2010-05-31 15:47
去查一下手册吧
DateDiff是计算两个时间的间隔。
如果你确定是这段代码在执行清空:
If DateDiff("d",rs("indate"),Date())<>0 then               
rs("inj")=0
rs("outj")=0
End If
那么他的意思就是时间间隔超过1天就执行清空,把0改为6,就是超过6天(也就是一周)执行清空操作。
如果你需要的是很明确哪个时间清空的,则不是这样写了,应该会比较复杂,因为ASP是需要有人浏览那个页面才会触发的,这个没想好在没人访问时,如何执行。
1