海外邮件中继,海外退信中继,美国高速VPS,不限流量VPN,邮局维护和管理,邮件网关,EMOS邮件中继,POSTFIX邮件中继,Winwebmail邮件中继,Winmail邮件中继,DBMail邮件中继,JDMail邮件中继,Exchange邮件中继,MDaemon邮件中继  淘宝店:http://shantan.taobao.com     云邮科技官网:www.yunrelay.com
【字体设置:大 中 小】
一般一个表都有一个唯一的标识,这里假设这个标识字段为ID 
 分四步: 
1、取得该表记录总数n。 
2、把所有的ID号存储到一个数组中IDs() 
3、产生一个不大于n的随机数m 
4、从数组中取出第m个ID号,查询数据表,取得记录数据。 
下面是代码(不包括数据库连接): 
<% 
dim stips() 
co=0 
set rs=server.createobject("adodb.recordset") 
sql="select [id] from stips" 
rs.open sql,conn,1,1 
if rs.eof and rs.bof then  
 response.write "还没有任何小知识哦!" 
else 
 do while not rs.eof  '循环保存id到数组 
    redim preserve stips(co) 
    stips(co)=rs("id") 
    co=co+1 
    rs.movenext 
 loop 
 rs.close 
 set rs=nothing 
 Randomize() 
 id=stips(int(rnd()*co)) '生成随机数,并查询数组内随机数对应的ID 
 set rs=server.createobject("adodb.recordset")   
 sql="select * from stips where id="&id  '查询数据库 
 rs.open sql,conn,1,1 
 response.write rs("content")   '这里假设数据库有一个content字段 
 rs.close  
 set rs=nothing 
end if 
conn.close 
set conn=nothing 
%>
        
	  
           
         发表评论 - 不要忘了输入验证码哦! 
        

 用户登陆
 用户登陆 站点日历
 站点日历 站点统计
 站点统计 最新评论
 最新评论 日志搜索
 日志搜索 
 
 随机访问数据库中某个表的一条记录   [ 日期:2010-03-09 21:18:16 ]   [ 来自:
 随机访问数据库中某个表的一条记录   [ 日期:2010-03-09 21:18:16 ]   [ 来自: