473,569 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select 4 records, Randomly from Database

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
2 2226
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******** *************** ***********@j20 g2000hsi.google groups.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
http://databases.aspfaq.com/database...om-record.html

Bob Lehmann

"tamaker" <ta*****@gmail. comwrote in message
news:78******** *************** ***********@j20 g2000hsi.google groups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2009
by: Bob Bedford | last post by:
I've a site where companies add their article. I'de like to provide a "lasts articles" table. By this, I'll show last articles inserted. But I won't always the same articles at any refresh. Question 1: how to get a "random" selection from the database, giving more priority to the last inserted (the ones with higher articleID) Question 2:...
26
3441
by: Chris Lasher | last post by:
Hello, I have a rather large (100+ MB) FASTA file from which I need to access records in a random order. The FASTA format is a standard format for storing molecular biological sequences. Each record contains a header line for describing the sequence that begins with a '>' (right-angle bracket) followed by lines that contain the actual...
4
6166
by: Bryan Harrington | last post by:
Can you use Select top 40 * from ... and ORDER BY... in the same query? I have the following 4 quearies that are.. for the most part, the same except the order by clause, all return a differnt amount of records. Thoughts? select top 40 * from q_work_list where assigned_to = 10 order by batch_date, remit_amt desc 40 records returned.
19
3520
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main form, the subform returns the records based on the two criteria. The criteria used on the main form are values selected in two list boxes. When the...
3
2662
by: neelesh kumar | last post by:
sir, i have a java applet j2sdk1.4.1_01 .i am using msaccess database . Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"). in my program i want to get records from access table in a new frame randomly(random records).In my frame i have next button now if i click next button, next record is coming from the table. i want to get random records from...
1
4014
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i...
1
1461
by: fran7 | last post by:
Hi, I have this code to randomly select an image from a sequence of fields in my database. Does anyone know if rather than random, one could simply move from one field to the next sequentialy. That would stop the problem of it randomly selecting the same field twice? The idea is that on page refresh the next pic is selected. It works a treat...
7
2269
by: wozza | last post by:
hi I'm a Dreamweaver user who's created a few simple data entry/ registrations forms in my time, but I'm not really a coder (though I can follow instructions and am not afraid to dabble...) - I generally make use of DW's builtin commands and some extensions. Anyway I'm creating a registration site for event exhibitors and I've been asked...
7
3137
ddtpmyra
by: ddtpmyra | last post by:
I have 400K records on my Access database. Now I wanted you pull out randomly records that falls on 79th records from top to bottom. How can you do that on sql? Your help is much appreciated. thanks, DM
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.