budapestnori
Technical User
Ok,I hope I can explain this. I have database with two fields one is an auto-increment ID and the other field is a string whose value is an image file name, such as w_img_1.jpg, w_img_2.jpg., etc.
When the page loads, I open the recordset and select all records, sorted by ID. Then, I use a rs.recordcount to determine the number of files. Once I have that number, I use that as my uppperbound in a loop to get get 9 random numbers between 1 and upperbound. That is working very well, but here is my problem. What I want, is each value of an array which is sized to 9., ie, nine random numbers, to contain the value of a unique image name. I am sure there are multiple ways to do this, I just need to know the most effecient. I thought of using the values of the record IDs, but these seem to change as they may be 1,2,3,5,38,43,54 of images are continually added and deleted. Here is the code I have so far:
Randomize
DIM cat,random_number(), counter, check,count
cat = Request("category"
Set cnn1 = Server.CreateObject("ADODB.Connection"
openStr = "driver={Microsoft Access Driver (*.mdb)};" & _
"dbq=" & Server.MapPath("database/images.mdb"
cnn1.Open openStr,"",""
sql = "SELECT * FROM gallery WHERE category = '" & cat & "' Order by ID"
Set rs = Server.CreateObject("ADODB.Recordset"
rs.Open sql, cnn1, 3, 3
count = rs.recordcount
redim random_number(count)
For counter = 1 to count
random_number(counter) = Int(Rnd * count)+1
for check=1 to counter-1
if random_number(check)= random_number(counter) then
counter=counter-1
end if
next
next
%>
<script type="text/javascript">
<!--
//Specify image paths and optional link (set link to "" for no link):
var dynimages=new Array()
<%
comma = ","
x = 0
while not rs.eof
response.write("dynimages[" & x & "]=[" & chr(34) & "images/gallery/" & rs("image"
& chr(34) & comma & Chr(34) & Chr(34) & "]" & chr(13))
x = x + 1
rs.movenext()
wend
%>
When the page loads, I open the recordset and select all records, sorted by ID. Then, I use a rs.recordcount to determine the number of files. Once I have that number, I use that as my uppperbound in a loop to get get 9 random numbers between 1 and upperbound. That is working very well, but here is my problem. What I want, is each value of an array which is sized to 9., ie, nine random numbers, to contain the value of a unique image name. I am sure there are multiple ways to do this, I just need to know the most effecient. I thought of using the values of the record IDs, but these seem to change as they may be 1,2,3,5,38,43,54 of images are continually added and deleted. Here is the code I have so far:
Randomize
DIM cat,random_number(), counter, check,count
cat = Request("category"
Set cnn1 = Server.CreateObject("ADODB.Connection"
openStr = "driver={Microsoft Access Driver (*.mdb)};" & _
"dbq=" & Server.MapPath("database/images.mdb"
cnn1.Open openStr,"",""
sql = "SELECT * FROM gallery WHERE category = '" & cat & "' Order by ID"
Set rs = Server.CreateObject("ADODB.Recordset"
rs.Open sql, cnn1, 3, 3
count = rs.recordcount
redim random_number(count)
For counter = 1 to count
random_number(counter) = Int(Rnd * count)+1
for check=1 to counter-1
if random_number(check)= random_number(counter) then
counter=counter-1
end if
next
next
%>
<script type="text/javascript">
<!--
//Specify image paths and optional link (set link to "" for no link):
var dynimages=new Array()
<%
comma = ","
x = 0
while not rs.eof
response.write("dynimages[" & x & "]=[" & chr(34) & "images/gallery/" & rs("image"
x = x + 1
rs.movenext()
wend
%>