View Full Version : Random Records... (again)
The Wizzard
03-09-2003, 12:44 AM
Hey Everyone,
I asked this question a few weeks ago, but wasnt really quite able to get it to work, so I think im going to ask again, and try to describe this a little different.
If you look at this http://www.tilocars.com everytime you refresh they display 4 random cars. This is exactly what I want to do. Grab 4 random car ID's (primary key) and then display 4-5 different details on the car, like they do, and then you click on it, and it takes you to the full page, i.e. details.asp?ID=2
hmm... I really hope I can get this one this time.
Thanks in advance for the help!!
ok. i think you need to brak it up in fout steps:
a. get the top value
b. generate random numbers
c. select the corresponding records
d. display them as a link.
a . Run a query like
sql="select Max(ID) as [topvalue] from table"
b. Use the returned value (rstop.fields("topvalue") )as top of an ASP randomize function.
c. build the sql statement. Using a loop
You'll need to run a loop wher first a random number is generated.
then you stick that number to the sql statement and run the randomize function again)
like this
sql = "select variables from table where ID="
count = 1
do while i <= numberofrecordstoreturn
num =random
if count = 1 then
sql = sql + num
else
sql = sql + " or " + num
run that statement.
d. build the link
<a href="thepage?id=<%rsselect.fields("ID")%>Link to page =<%rsselect.fields("ID")%> etc
ok. i think you need to brak it up in fout steps:
a. get the top value
b. generate random numbers
c. select the corresponding records
d. display them as a link.
a . Run a query like
sql="select Max(ID) as [topvalue] from table"
b. Use the returned value (rstop.fields("topvalue") )as top of an ASP randomize function.
c. build the sql statement. Using a loop
You'll need to run a loop wher first a random number is generated.
then you stick that number to the sql statement and run the randomize function again)
like this
sql = "select variables from table where ID="
count = 1
do while i <= numberofrecordstoreturn
num =random
if count = 1 then
sql = sql + num
else
sql = sql + " or " + num
end if
count = count + 1
i = i+ 1
next
run that statement.
d. build the link
<a href="thepage?id=<%rsselect.fields("ID")%>Link to page =<%rsselect.fields("detail")%> etc
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.