CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Pulling more than one random record?

Print topic Send  topic

Author Message
brandx


Posts: 29
Posted: 10/27/2004, 3:44 PM

Codecharge Studio 2.3
ASP/Access

Hi all

I've got some asp working so that it pulls one random record from the database. What i would really like it to do is to pull a few random records....

Here's what i have so far.

<%
' ADO Constant. Dont change this
Const adCmdText = &H0001

' Connection string and SQL statement
Dim query, connStr
query = "select TBody, TAuthor from Testimonial"
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("path\database.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><i>" & rs("TAuthor") & "</i></b><br>" & rs("TBody")

' Closing the database
rs.Close
Set rs = Nothing
%>

As you can see by the table and field names... this little app pulls one testimonial from the database... I would like it to pull...say..... 5 testimonials from the database randomly....

Any ideas?

Geary
View profile  Send private message
mrachow


Posts: 509
Posted: 10/28/2004, 12:53 AM

Do you have some kind of primary key there?
In a first query I would select all keys.
Choose 5 of them by random number like you had done it for one.
With a second query select these 5 testimonials saying where ... IN(<these 5 values>) .

BTW
If the number of testimonials stays equal is a different testimonial selected by your current solution?
If not use Randomize before calling RND.

Regards,
Michael
_________________
Best regards,
Michael
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.