Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

weighting of random selection

Status
Not open for further replies.

sfunk

Technical User
Jan 22, 2002
107
US
Hello,

I have a script that randomly (yes, I know it's not truely random) selects a record from a record set. I would like to add a field to the table that can be used to weight each record in how often it is selected. Here is the script I'm currently using. I appreciate any help.


<%
Dim conn, rs, connString, sql, recCount, rec

set conn = server.CreateObject(&quot;adodb.connection&quot;)
set rs = server.CreateObject(&quot;adodb.recordset&quot;)
conn.Open connString

sql = &quot;select Listing_ID from Listings&quot;
rs.Open sql, conn, 3

recCount = rs.RecordCount

rs.close
conn.Close
set rs=nothing
set conn=nothing

randomize
rec = int(rnd * recCount)

set conn=server.CreateObject(&quot;adodb.connection&quot;)
conn.open connString

sql = &quot;Select * from Listings Order By Listing_ID&quot;
set rs=conn.execute(sql)

rs.MoveFirst
rs.Move rec
%>
<table>
<tr><td><%= rs(0) %></td></tr>
<tr><td><%= rs(1) %></td></tr>
<tr><td><%= rs(2) %></td></tr>
<tr><td><%= rs(3) %></td></tr>
</table>
<%
rs.Close
conn.close
set rs=nothing
set conn=nothing
%>


Sincerely,
Steve
 
Awe come on people! Don't make me go out and buy a solution. I'll do it. Don't make me do it. I sware I will.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top