<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<% "一个从数据库中随机读取纪录的例子
Set Rs1=server.CreateObject ("adodb.recordset")
Set Rs=server.CreateObject ("ADODB.RECORDSET")
SQL="Select id from Article order by id desc"
rs.Open sql,dataconn,3,3
If not rs.EOF then
total=rs("id") "取最大的ID
rs.Close
Randomize
R=Int((total - 1+ 1) * Rnd + 1)
SQL="Select id,content from Article where id="& R
rs.Open sql,dataconn,3,3
if not rs.EOF then
content=RS("content")
content=replace(content,chr(10),"<br>")
content=replace(content,chr(13),"<br>")
content=replace(content,"<br><br>","<br>")
Response.Write content
else
sql1="select content from Article"
rs1.Open sql1,dataconn,3,3
if not eof then
"取第一条纪录作为默认的显示纪录
content=RS1("content")
content=replace(content,chr(10),"<br>")
content=replace(content,chr(13),"<br>")
content=replace(content,"<br><br>","<br>")
Response.Write content
else
"数据库为空
Response.Write "不存在"
end if
rs1.Close
end if
Rs.Close
end if
set Rs=nothing
%>
这是一个使用ASP从数据库中随机选取记录的示例代码。首先,通过SQL查询获取最大的ID,然后利用Rnd函数生成随机数以选择特定ID的记录。接着,处理选取的记录内容,将换行符替换为HTML的<br>标签,以便在网页中正确显示。如果数据库为空,代码会显示默认的记录或者提示信息。
1937

被折叠的 条评论
为什么被折叠?



