214-564-5316
Wednesday, May 21, 2008
•
Portfolio
•
FAQ's
•
Pricing
•
Request Info
•
Code Examples
•
Demos
•
Marketing
•
Tutorials
•
Downloads
•
Refresh the page to generate random database results
Mike Mac
Tool Time
Sally Amith
Jon Blade
Samuel Clemens
Here is the code:
<%@ LANGUAGE="VBSCRIPT" %> <% Option Explicit %> <!--#include virtual="/ADOVBS.inc"--> <% Dim Conn,RS,strSQL,strConnection,str,str1,cnt,cnt1,rndMax,RndNumber,sql strConnection="Provider=MICROSOFT.JET.OLEDB.4.0; " & "DATA SOURCE=" & Server.MapPath("/yourdatabase.mdb") strSQL = "SELECT id FROM yourtable" set Conn = Server.CreateObject("ADODB.Connection") Set Rs = Server.CreateObject("ADODB.Recordset") Conn.Open strConnection set Rs.ActiveConnection = Conn Rs.LockType = adLockOptimistic Rs.CursorType = adOpenKeySet Rs.Open strSQL Rs.MoveLast cnt = Rs.RecordCount cnt1 = cnt rndMax = cnt 'change the number of results returned here (5) If CInt(5) < cnt Then cnt1 = CInt(5) End If str = "," str1 = "," Do Until cnt1 = 0 Randomize RndNumber = Int(Rnd * rndMax) If (InStr(1, str1, "," & RndNumber & "," ) = 0) Then str1 = str1 & RndNumber & "," cnt1 = cnt1 - 1 Rs.MoveFirst Rs.Move RndNumber str = str & Rs("id") & "," End If Loop Rs.Close Set Rs = Nothing sql = "SELECT * FROM yourtable WHERE (((InStr(1,'" & str & "',(',' & [id] & ',')))<>0)) " Set Rs = Server.CreateObject("ADODB.Recordset") set Rs.ActiveConnection = Conn Rs.LockType = adLockOptimistic Rs.CursorType = adOpenKeySet Rs.Open sql %> <html> <head> <title>Retrieve Random Records</title>< <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <% 'Display the returned records here as you like Do While Not rs.EOF Response.Write(rs("Field_One") & " " & rs("Field_Two") & "<BR>") rs.MoveNext Loop %> </body> </html> <% Rs.Close Set Rs = Nothing Conn.Close Set Conn = Nothing %>
•
Home
•
Contact Us
•
Terms of Service
•
Privacy Policy
•
Email Policy
•
Hosting
•
Links
•
Site Search
•