navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

How do I get a random record from a database?

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> How do I get a random record from a database?
Page: [1]
 
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 >
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Random result - 7/6/2001 20:18:00   
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=65

< Message edited by Spooky -- 9/24/2002 10:28:59 PM >

(in reply to Mvu)
Lydecker

 

Posts: 609
From: Oxshott, Surrey, England (UK)
Status: offline

 
RE: Random result - 8/19/2002 10:01:17   
I would like to do the same - display 1 result from a DRW, but make it random. Spooky' s link no longer works :)

(in reply to Mvu)
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

(in reply to Mvu)
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Random result - 8/19/2002 23:22:49   
Or heres a trick using SQL2000 :

" ... order by NewID() "

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to Mvu)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> How do I get a random record from a database?
Page: [1]
Jump to: 1





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