By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Select 4 records, Randomly from Database

P: n/a
Is this do-able with ASP / VBscript?

-- I have a database with user records (name, photo, etc. etc.)

I want to use asp to generate (on the homepage) a series of 4 randomly
selected 'user records' from the database -- say just the headshot
photo or name from the database.

In addition to the recordset being randomly generated (i.e. our of
about 50 records, only records 4, 18, 23 and 26 are displayed) I need
to MAKE SURE they are not duplicated (i.e. out of the 50 records,
records 4, 18, 23 and 23 -- where the last two are duplicates).

Is there a way I can pull this off and how do I go about it exactly?
Thanks!

Dec 12 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
1) get the number of records (users in the database)
2) generate 4 random numbers, make sure that they are not the same, and the
they are not higher than the total number of users (let's say that you got
12,25,28 and 30)
3) choose the highest number that you selecte (among the 4 random numbers)
(that will be 30)
4) select top 30 * from users (assuming that 30 is the highest number). This
will get 30 users from the database
5) loop thru the records, when you're at the random numbers, display them
(meaning that you display only 12,25,28 and 30).

This isn't the most optimized way, but try it and make it work. You can
always tweak it later.

Hope this helps
B

"tamaker" <ta*****@gmail.comwrote in message
news:78**********************************@j20g2000 hsi.googlegroups.com...
Is this do-able with ASP / VBscript?

-- I have a database with user records (name, photo, etc. etc.)

I want to use asp to generate (on the homepage) a series of 4 randomly
selected 'user records' from the database -- say just the headshot
photo or name from the database.

In addition to the recordset being randomly generated (i.e. our of
about 50 records, only records 4, 18, 23 and 26 are displayed) I need
to MAKE SURE they are not duplicated (i.e. out of the 50 records,
records 4, 18, 23 and 23 -- where the last two are duplicates).

Is there a way I can pull this off and how do I go about it exactly?
Thanks!

Dec 12 '07 #2

P: n/a
http://databases.aspfaq.com/database...om-record.html

Bob Lehmann

"tamaker" <ta*****@gmail.comwrote in message
news:78**********************************@j20g2000 hsi.googlegroups.com...
Is this do-able with ASP / VBscript?

-- I have a database with user records (name, photo, etc. etc.)

I want to use asp to generate (on the homepage) a series of 4 randomly
selected 'user records' from the database -- say just the headshot
photo or name from the database.

In addition to the recordset being randomly generated (i.e. our of
about 50 records, only records 4, 18, 23 and 26 are displayed) I need
to MAKE SURE they are not duplicated (i.e. out of the 50 records,
records 4, 18, 23 and 23 -- where the last two are duplicates).

Is there a way I can pull this off and how do I go about it exactly?
Thanks!

Dec 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.