|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Select a random record from the database
I have what I hope is a simple question-I am working on an ASP page that lets people post entries to an MS Access database. When they are done, it goes back to the main page, where it will list all of the entries - that's the easy part.
What I would like to do is this: On the page that lists the entries (problemlist.asp), I want it to be able to check the database to see how many total entries there, then pick one at random to display. It should also do this every time the page is refreshed (if you've ever been to lowbrow.com, you'll know what I mean )Any suggestions/help would be greatly appreciated! |
|
#2
|
||||
|
||||
|
With SQL Server it can be done with a simple select statement. I don't know about Access, but...
Does your table have a field with unique ids? You can generate a random number with VBScript then run the query with the random number: nTop = "select count(id) from table1" ... Randomize ' Generate random value between 1 and nTop . nRandom= Int((nTop * Rnd) + 1) sql = "select * from table1 where id = " & nRandom |
|
#3
|
|||
|
|||
|
Well, I got it to generate a random number based on the total number of entries in the database, but I cant figure out how to get it to pull the information from the entry that corresponds to the random number....
Do SQL commands work on an Access database? |
|
#4
|
||||
|
||||
|
Do your records have ids associated with them?
Append the random number at the end of the sql query that you execute against the database like this: "select * from table1 where id = " & nRandom ...nRandom is the random number you generated. Translates to something like: select * from table1 where id = 145 |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > Select a random record from the database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|