close
access:
SELECT top 10 * FROM 表 ORDER BY Rnd(id)
Rnd(id) 其中的id是自動編號字段,可以利用其他任何數值來完成
rnd()果然可以隨機提取數據,但是有一個問題,就是他只能隨機一次,下次打開這個頁面隨機的內容沒有改變,跟上次隨機的是一樣的,我希望每次刷新選出的數據是不同的,該如何解決呢。
代碼如下
<%
Dim minglu
Dim minglu_numRows
Set minglu = Server.CreateObject("ADODB.Recordset")
minglu.ActiveConnection = MM_beta_commercial_STRING
minglu.Source = "SELECT top 15 * FROM company ORDER BY rnd(id)"
minglu.CursorType = 0
minglu.CursorLocation = 2
minglu.LockType = 1
minglu.Open()
minglu_numRows = 0
%>
用這個變通的方法
Randomize
upperbound = 20
lowerbound = 1
x = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
dim Orderby
Orderby = "id"
for i = 0 to x
Orderby = "Rnd("& Orderby &")"
next
'str = str & Orderby & vbnewline
sql = "SELECT top 10 id FROM a ORDER BY "&Orderby
SELECT top 10 * FROM 表 ORDER BY Rnd(id)
Rnd(id) 其中的id是自動編號字段,可以利用其他任何數值來完成
rnd()果然可以隨機提取數據,但是有一個問題,就是他只能隨機一次,下次打開這個頁面隨機的內容沒有改變,跟上次隨機的是一樣的,我希望每次刷新選出的數據是不同的,該如何解決呢。
代碼如下
<%
Dim minglu
Dim minglu_numRows
Set minglu = Server.CreateObject("ADODB.Recordset")
minglu.ActiveConnection = MM_beta_commercial_STRING
minglu.Source = "SELECT top 15 * FROM company ORDER BY rnd(id)"
minglu.CursorType = 0
minglu.CursorLocation = 2
minglu.LockType = 1
minglu.Open()
minglu_numRows = 0
%>
用這個變通的方法
Randomize
upperbound = 20
lowerbound = 1
x = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
dim Orderby
Orderby = "id"
for i = 0 to x
Orderby = "Rnd("& Orderby &")"
next
'str = str & Orderby & vbnewline
sql = "SELECT top 10 id FROM a ORDER BY "&Orderby
全站熱搜
留言列表