|
| |
|
|
Mvu
Posts: 108 From: Brussels Belgium Status: offline
|
How do I get a random record from a database? - 7/5/2001 14:24:00
Hi,<P>I would like to have the records of a particular query not sorted by " Ascendant" or " Descendant" , but randomly. One of the record is numeric and " Numero Auto" . I guess that is the best record to use in this case.<BR>Has someone a solution for me ?
< Message edited by Spooky -- 11/24/2002 3:29:31 PM >
|
|
|
|
Eli
Posts: 2658 From: ... er ... Status: offline
|
RE: Random result - 8/19/2002 17:23:46
<% ' ADO Constant. Dont change this Const adCmdText = &H0001 ' Connection string and SQL statement Dim query, connStr query = " select field1, field2, field3 from table" connStr = " Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(" YOURDATABASE.mdb" ) ' Opening database Dim rs Set rs = Server.CreateObject(" ADODB.Recordset" ) rs.Open query, connStr, 3, , adCmdText ' Generating random number from total number of records Dim intRnd Randomize Timer intRnd = (Int(RND * rs.RecordCount)) ' Now moving the cursor to random record number rs.Move intRnd ' Showing the random statement Response.Write " <b>" & rs(" field1" ) & " , in </b>" Response.Write " <b>" & rs(" field2" ) & " </b>" %> Response.Write " <b>" & rs(" field3" ) & " </b>" ' Closing the database rs.Close Set rs = Nothing %>
_____________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|