ordering arrays

1. Junior Member
Join Date
Dec 1969
Posts
7

ordering arrays

Hi all, I have a serries of arrays that I want to arrange descending by the second part of the array.<BR>eg.<BR>array1 = cat/22<BR>array2 = dog/10<BR>array3 = pig/30<BR>array4 = horse/5<BR><BR>I want them to be ordered like...<BR><BR>position1 = array3<BR>position2 = array1<BR>position3 = array2<BR>position4 = array4<BR><BR>This could possably be a serries of 100 arrays i need to order.<BR>How would you do it?

2. Senior Member
Join Date
Dec 1969
Posts
1,849

http://www.4guysfromrolla.com/demos/bubblesort.asp<BR><BR>There are many other ways of doing it, its been done before, do some searching you will find more code than what you know what to do with...<BR><BR>-- Whol

3. Senior Member
Join Date
Dec 1969
Posts
6,476

RE: ordering arrays

This could possably be a serries of 100 arrays i need to order.<BR><BR>100 Arrays?<BR>or<BR>1 array with 100 elements?<BR>Big diff between the 2.<BR>In the top right corner is link to the faqs<BR>look under category arrays<BR>There are examples there on how to sort arrays...<BR><BR>Now. if it really 100 different arrays<BR>You will need an Array of the Arrays<BR><BR>arrMyArays(0) = Array1<BR>arrMyArays(1) = Array2<BR>arrMyArays(2) = Array3<BR>arrMyArays(3) = Array4<BR><BR>Then you can sort on that array<BR>Or build it in the order you need to begin with??<BR>

4. Senior Member
Join Date
Dec 1969
Posts
6,476

You Broke my heart

in 2 seconds ;-)<BR>hehehe

5. Senior Member
Join Date
Dec 1969
Posts
1,849

I'd have been sooner

But I was searching on google ;-)<BR><BR>hehehehehe.

6. Junior Member
Join Date
Dec 1969
Posts
7

RE: ordering arrays

still not quite what i need and can&#039;t find it by searching google either. lots about ordering within an array. I need to order a serries of arrays with two items in each array, and do the ordering on the second item in that array but keeping the two items linked.<BR><BR>eg. <BR>array1 = cat/22 <BR>array2 = dog/10 <BR>array3 = pig/30 <BR>array4 = horse/5 <BR><BR>I want them to be ordered like... <BR><BR>position1 = array3 <BR>position2 = array1 <BR>position3 = array2 <BR>position4 = array4 <BR><BR>This could possably be a serries of 100 arrays i need to order. <BR>How would you do it? <BR>Perhaps I need to split the arrays first order the second part then relink them. But not sure how I would do that efficiantly with a lot of arrays.

7. Senior Member
Join Date
Dec 1969
Posts
6,476

RE: ordering arrays

As I said (Since your dealing with totally different arrays)<BR><BR>Is to have an array to hold the arrays and the ordering..<BR><BR>arrArrayOrder(0) = array0<BR>arrArrayOrder(1) = array1<BR>arrArrayOrder(2) = array2<BR>arrArrayOrder(3) = array3<BR><BR><BR>NOW im not understanding 1 thing<BR>you say this<BR>array1 = cat/22 <BR>array2 = dog/10 <BR>array3 = pig/30 <BR>array4 = horse/5 <BR>IS your arrays and there would be 100&#039;s<BR><BR><BR>Are you saying this is an array as is?<BR>array1 = "cat/22" as being the only element/value?<BR>and no more?<BR><BR>If so your dead wrong in thinking thats an array<BR>an array would be something like<BR>array1(0) = "cat/22"<BR>array1(1) = "cat/24"<BR>array1(2) = "cat/45"<BR>array1(3) = "cat/78"<BR><BR>Now thats an array.<BR>So maybe this is what you have with 100&#039;s of elements inside the 1 array?<BR><BR>If not<BR>Show a sample of exactly what you have in an array<BR>and how your building that array to start with...<BR><BR>Then with better understanding maybe we can help out a bit better...<BR><BR>

8. Junior Member
Join Date
Dec 1969
Posts
7

RE: ordering arrays

Ok, I have the following code ... <BR><BR>***********************************<BR>S et paidSearchResults = Server.CreateObject("ADODB.Recordset")<BR>paidSQL = "SELECT * FROM tblWebsites "<BR><BR> For intSQLLoopCounter = 0 To UBound(sarySearchWord)<BR> paidSQL = paidSQL & "WHERE paidwords LIKE &#039;%" & sarySearchWord(intSQLLoopCounter) & "%&#039;"<BR> If request.querystring("wherefrom") = "NewZealandSearch" or request.form = "New Zealand Search" Then<BR> paidSQL = paidSQL & " And country = " & bastr(".nz") & ""<BR> End If<BR> Next<BR>paidSearchResults.Open paidsql, strCon, 3<BR><BR>&#039;Count the number of records found<BR>lngTotalRecordsFound = CLng(paidSearchResults.RecordCount)<BR> <BR>Do while not paidSearchResults.eof<BR> <BR>For intSQLLoopCounter = 0 To UBound(sarySearchWord)<BR> spaidwords = paidSearchResults.Fields("paidwords") <BR> <BR> If Len(Trim(spaidwords)) &#062; 3 Then<BR> arrpaidwords = split(spaidwords,"/")<BR> <BR> For iQs = 0 To ubound(arrpaidwords)-1<BR> arrwordcost = split(arrpaidwords(iQs),",")<BR> <BR> <BR> if strcomp(arrwordcost(0),sarySearchWord(intSQLLoopCo unter),1) = 0 Then<BR> <BR> arrlist = arrlist&paidSearchResults.Fields("siteidno")&","&a rrwordcost(1)&"/"<BR> <BR> End If<BR> Next<BR><BR> End If<BR>next<BR><BR>paidSearchResults.MoveNext<BR>Lo op<BR><BR>arrpaidsites = arrlist <BR>******************************************<BR> It is getting data from a database field that could be populated like cat,.33/dog,.10/horse,.55/<BR><BR>so if more than one person has inputted data with a value for dog then arrpaidsites could equal 1860,.10/2234,.89/2567,.35 where the first number is the id for the data on the database and the second is the number I want to sort it by descending.<BR>In the end I want to display results from the database in this case for 1860 then 2567 then 2234<BR><BR>Hope this helps you to help me.<BR>Thank you, John.<BR>

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•