ASP 高手帮忙修改一下,实在做不了?
SetCONN=Server.CreateObject("ADODB.Connection")strKw=safestr(request("keyword"))CONN....
Set CONN=Server.CreateObject("ADODB.Connection")
strKw=safestr(request("keyword"))
CONN.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.Mappath("ok.mdb")
sql="select * from dey where 1=1"
if strKw<>"" and strKw<>"请输入关键字" then
sql=sql & " and kwd like '%" & strKw & "%'"
end if
sql=sql & " order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if not rs.eof then
DIM Appeared
Call DisRndRecord(10,rs.recordCount)'调用函数该位置显示记录
'################SUBS################
'#DisRndRecord(DisNum,rsBound)
'#参数DisNum:显示数量
'#参数rsBound:随机数产生范围
Sub DisRndRecord(DisNum,rsBound)
DIM i,ThisRnd
If rsBound < DisNum Then DisNum = rsBound'记录总数小于要抽取记录条数的情况
For i = 0 To DisNum - 1
ThisRnd = GetRnd(rsBound)'取得一个不重复的随机数
rs.Move(ThisRnd)'游标移动到随机数位置数读取
Response.Write(rs("kwd")&"<br>")
'Response.Write("("&rs("id")&")"&rs("kwd"))
rs.Move(-ThisRnd)
Next
End Sub
'# 函数GetRnd(bound)返回一个不重复的随机数字
'#参数bound:随机范围
Function GetRnd(bound)
DIM ranNum
Randomize()
ranNum=int(bound*rnd)
If Instr(Appeared,"["&ranNum&"]") Then'产生的随机数是否出现过
ranNum = getRnd(bound)
End If
Appeared = Appeared & "["&ranNum&"]"'记录已出现的随机数
GetRnd = ranNum
End Function
else
set rs=nothing
name=trim(request("keyword"))
sql="select top 10 * from dey order by Rnd(second(now()))"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
dim i
i=0
%>
<%do while not rs.eof%>
<font color="66cc00"><%=rs("kwd")%></font><br><br>
<%i=i+1
if i>=10 then exit do
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>
能不能随机实现循环,最上面的一句,让它在查询到数据库中的记录后,再加9条记录填充到10条或者最多15条?
上面的语句可以实现随机循环,而ELSE后的却不能实现循环了,大哥们,怎么能让ELSE后的也能最少10条最多15条中随机循环起来? 展开
strKw=safestr(request("keyword"))
CONN.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.Mappath("ok.mdb")
sql="select * from dey where 1=1"
if strKw<>"" and strKw<>"请输入关键字" then
sql=sql & " and kwd like '%" & strKw & "%'"
end if
sql=sql & " order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if not rs.eof then
DIM Appeared
Call DisRndRecord(10,rs.recordCount)'调用函数该位置显示记录
'################SUBS################
'#DisRndRecord(DisNum,rsBound)
'#参数DisNum:显示数量
'#参数rsBound:随机数产生范围
Sub DisRndRecord(DisNum,rsBound)
DIM i,ThisRnd
If rsBound < DisNum Then DisNum = rsBound'记录总数小于要抽取记录条数的情况
For i = 0 To DisNum - 1
ThisRnd = GetRnd(rsBound)'取得一个不重复的随机数
rs.Move(ThisRnd)'游标移动到随机数位置数读取
Response.Write(rs("kwd")&"<br>")
'Response.Write("("&rs("id")&")"&rs("kwd"))
rs.Move(-ThisRnd)
Next
End Sub
'# 函数GetRnd(bound)返回一个不重复的随机数字
'#参数bound:随机范围
Function GetRnd(bound)
DIM ranNum
Randomize()
ranNum=int(bound*rnd)
If Instr(Appeared,"["&ranNum&"]") Then'产生的随机数是否出现过
ranNum = getRnd(bound)
End If
Appeared = Appeared & "["&ranNum&"]"'记录已出现的随机数
GetRnd = ranNum
End Function
else
set rs=nothing
name=trim(request("keyword"))
sql="select top 10 * from dey order by Rnd(second(now()))"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
dim i
i=0
%>
<%do while not rs.eof%>
<font color="66cc00"><%=rs("kwd")%></font><br><br>
<%i=i+1
if i>=10 then exit do
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>
能不能随机实现循环,最上面的一句,让它在查询到数据库中的记录后,再加9条记录填充到10条或者最多15条?
上面的语句可以实现随机循环,而ELSE后的却不能实现循环了,大哥们,怎么能让ELSE后的也能最少10条最多15条中随机循环起来? 展开
3个回答
展开全部
<%
'# 函数GetRnd(bound)返回一个不重复的随机数字
'#参数bound:随机范围
Function GetRnd(bound)
DIM ranNum
Randomize()
ranNum=int(bound*rnd)
If Instr(Appeared,"["&ranNum&"]") Then'产生的随机数是否出现过
ranNum = getRnd(bound)
End If
Appeared = Appeared & "["&ranNum&"]"'记录已出现的随机数
GetRnd = ranNum
End Function
'################SUBS################
'#DisRndRecord(DisNum,rsBound)
'#参数DisNum:显示数量
'#参数rsBound:随机数产生范围
Sub DisRndRecord(DisNum,rsBound)
DIM i,ThisRnd
If rsBound < DisNum Then DisNum = rsBound'记录总数小于要抽取记录条数的情况
For i = 0 To DisNum - 1
ThisRnd = GetRnd(rsBound)'取得一个不重复的随机数
rs.Move(ThisRnd)'游标移动到随机数位置数读取
Response.Write(rs("kwd")&"<br>")
'Response.Write("("&rs("id")&")"&rs("kwd"))
rs.Move(-ThisRnd)
Next
End Sub
Set CONN=Server.CreateObject("ADODB.Connection")
strKw=safestr(request("keyword"))
CONN.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.Mappath("ok.mdb")
sql="select * from dey where 1=1"
if strKw<>"" and strKw<>"请输入关键字" then
sql=sql & " and kwd like '%" & strKw & "%'"
end if
sql=sql & " order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if not rs.eof then
DIM Appeared
Call DisRndRecord(10,rs.recordCount)'这里面的10就是调用多少条记录 改成15就是输出15条
rs.close
set rs=nothing
else
name=trim(request("keyword"))
sql="select * from dey order by Rnd(second(now()))"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
Call DisRndRecord(10,rs.recordCount)'这里面的10就是调用多少条记录 改成15就是输出15条
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>
'# 函数GetRnd(bound)返回一个不重复的随机数字
'#参数bound:随机范围
Function GetRnd(bound)
DIM ranNum
Randomize()
ranNum=int(bound*rnd)
If Instr(Appeared,"["&ranNum&"]") Then'产生的随机数是否出现过
ranNum = getRnd(bound)
End If
Appeared = Appeared & "["&ranNum&"]"'记录已出现的随机数
GetRnd = ranNum
End Function
'################SUBS################
'#DisRndRecord(DisNum,rsBound)
'#参数DisNum:显示数量
'#参数rsBound:随机数产生范围
Sub DisRndRecord(DisNum,rsBound)
DIM i,ThisRnd
If rsBound < DisNum Then DisNum = rsBound'记录总数小于要抽取记录条数的情况
For i = 0 To DisNum - 1
ThisRnd = GetRnd(rsBound)'取得一个不重复的随机数
rs.Move(ThisRnd)'游标移动到随机数位置数读取
Response.Write(rs("kwd")&"<br>")
'Response.Write("("&rs("id")&")"&rs("kwd"))
rs.Move(-ThisRnd)
Next
End Sub
Set CONN=Server.CreateObject("ADODB.Connection")
strKw=safestr(request("keyword"))
CONN.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.Mappath("ok.mdb")
sql="select * from dey where 1=1"
if strKw<>"" and strKw<>"请输入关键字" then
sql=sql & " and kwd like '%" & strKw & "%'"
end if
sql=sql & " order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if not rs.eof then
DIM Appeared
Call DisRndRecord(10,rs.recordCount)'这里面的10就是调用多少条记录 改成15就是输出15条
rs.close
set rs=nothing
else
name=trim(request("keyword"))
sql="select * from dey order by Rnd(second(now()))"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
Call DisRndRecord(10,rs.recordCount)'这里面的10就是调用多少条记录 改成15就是输出15条
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询