random

This is a discussion on "random" within the Classic ASP section. This forum, and the thread "random are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Reply
 
LinkBack (1) Thread Tools
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old Jul 17th, 2005, 19:59
Highly Reputable Member
Join Date: May 2005
Location: U.K
Age: 21
Posts: 739
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbramz
random

hi

how would you go about selecting a random record from a database?

basicly i want a page, and when you hit it a random record from the database is displayed. so if i was to refresh the page, you would see another (random) record

cheers
Reply With Quote

  #2 (permalink)  
Old Jul 17th, 2005, 20:31
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Access or SQL?
Reply With Quote
  #3 (permalink)  
Old Jul 17th, 2005, 21:17
Highly Reputable Member
Join Date: May 2005
Location: U.K
Age: 21
Posts: 739
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbramz
access
Reply With Quote
  #4 (permalink)  
Old Jul 18th, 2005, 01:16
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
http://www.webforumz.com/viewtopic.p...=access+random
Reply With Quote
  #5 (permalink)  
Old Jul 18th, 2005, 01:42
Highly Reputable Member
Join Date: May 2005
Location: U.K
Age: 21
Posts: 739
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbramz
ha! lol never saw that post 5 from the top

however, im stuck. basicly im editing a script i downloaded. its the page that shows all the entries of the database. However, im not sure where or what to edit to make the RND function work.

Code: Select all
  <%
  dim Connect, SHOWALL, Query 
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath("db.mdb"))
Set SHOWALL = Server.CreateObject("ADODB.Recordset")
Query = "SELECT * FROM records"
SHOWALL.Open Query, Connect, adOpenDynamic, adLockOptimistic
SHOWALL.movefirst
do while not SHOWALL.eof
%>
how do i edit this? and whats the basic connection to the db, cos i know some of that is extra, just dont know what.
(is it this?)
Code: Select all
  <%
  dim Connect, SHOWALL, Query 
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath("db.mdb"))
Query = "SELECT * FROM whatever"
%>
with regards
Reply With Quote
  #6 (permalink)  
Old Jul 18th, 2005, 05:01
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Ack, it's not the way I usually write this stuff but this is the basic connection part

Code: Select all
Set Connect = Server.CreateObject("ADODB.Connection") 
Connect.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath("db.mdb"))
And to get one random one you want to change

Code: Select all
Query = "SELECT * FROM records"
to
Code: Select all
Randomize()
intRandomNumber = Int (1000*Rnd)+1


Query = "SELECT TOP 1 *,Rnd(" & -1 * (intRandomNumber) & "*TableID) AS rid  FROM records ORDER BY rid"
replacing TableID with the name of the id field for the table.

I haven't tested it but unless I made a typo that should work.
Reply With Quote
Reply

Tags
random

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.webforumz.com/classic-asp/2670-random.htm
Posted By For Type Date
Computer!Totaal :: Bekijk onderwerp - Een willekeurig record ophalen (C#, ASP.NET) This thread Refback May 6th, 2008 19:21

Similar Threads
Thread Thread Starter Forum Replies Last Post
Random div background Narcassa JavaScript Forum 5 Apr 9th, 2008 18:54
Random .swf on refresh jtyoungs JavaScript Forum 2 Sep 19th, 2007 12:48
random opening image berjoe Flash & Multimedia Forum 3 Oct 11th, 2006 01:27
how to make random questions? selphie08 Flash & Multimedia Forum 5 Sep 18th, 2006 01:48
Random records.. u2orange Databases 6 Mar 8th, 2004 09:31


All times are GMT. The time now is 20:57.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43