Random Results in A Searchy Query HELP!! (Full Version)

All Forums >> [Web Development] >> ASP, PHP, and Database



Message


webgyrl -> Random Results in A Searchy Query HELP!! (10/28/2009 18:51:42)

Hey guys,
I have a site that list people and their skills and i wanted every time someone ran a search based on their select criterias the order of the results would change. In other words i want all the people to get a fair shot at being on the top of the list. Is their anyway i can make the results show up in random order every time or at least half the time? am using asp and frontpage.




TexasWebDevelopers -> RE: Random Results in A Searchy Query HELP!! (10/29/2009 9:21:28)

Randomizing record retrieval is a bit more complicated than it might seem at first blush. First, you need to find a cound of the records..you cannot randomize without that information:
cnt1 = cnt
rndMax = cnt
If CInt(5) < cnt Then
cnt1 = CInt(5)
End If

Then we need to create a random number based on the count:
RndNumber = Int(Rnd * rndMax)

Next its time to randomize the results
If (InStr(1, str1, "," & RndNumber & "," ) = 0) Then
str1 = str1 & RndNumber & ","
cnt1 = cnt1 - 1
Rs.MoveFirst
Rs.Move RndNumber
str = str & Rs("id") & ","
End If
Loop

The full code and example are here:

http://www.texaswebdevelopers.com/examples/retrieverandomrecords.asp




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
6.347656E-02