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!

Ranking an array of records...

Status
Not open for further replies.

mclh

Technical User
Jun 13, 2001
8
GB
Can anyone point me to an algorithm, pref. vbscript, for sorting an array containing data such as follows ('|' represents the delimiter for the array's dimensions):

Mary | April | 1983
Fred | June | 1982
Peter | January | 1978
Jude | December | 1992
Paul | April | 1991

...so that if I want to sort the results by the search term 'apr', Mary's would score the highest and if I sorted by 'apr' and '198' that Mary would rank higher than Paul.

As hopefully you can see I want to enable users to search by multiple search terms and then to rank the results by those terms. I guess I need to score each array element by each search term?
 
You could do this in your SQL fairly easily. Build the base of your SELECT statement and case statement for each scenario you want.

sqlflag=request("sqlflag")

SQL = "SELECT * FROM data_table"

select case(builder)
case 1
'sort by name in descending order
SQL = SQL & " SORT BY name DESC"
case 2
'sort by name in ascending order
SQL = SQL & " SORT BY name ASC"
etc.
end case

then make the column names into href's that do a response.redirect back to the same page with additional SQL
to do the sort the way you want. So:

response.redirect "mypage.asp?sqlflag='1'"

hth
mb
:)


"Where's the Ka-Boom? There's supposed to be an Earth-shattering Ka-Boom!"
Marvin the Martian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top