Solved

Sort multidimensional array in ASP

Posted on 2004-08-25
14
316 Views
Last Modified: 2009-12-16
Hi,

I have a multidimensional array (28 columns, unlimited rows) which I am trying to sort. I have tried various scripts which I have found on the internet but so far have nothing that actually works. Any help wpuld be much appreciated.

thanks
0
Comment
Question by:brucegm
  • 2
  • 2
  • 2
  • +5
14 Comments
 
LVL 4

Expert Comment

by:jcrumble
ID: 11892823
Depending on the functionality you are after you might have better luck using XML.  If your primarily dealing with the information on the client side (ie select a value in one drop down list to populate the values in a secondary drop down list etc), you could empty everything into a JavaScript Array that you parse using substrings on the client side when drop downs are selected.  However, based on the size of your array I hope this is not the scenario.  What exactly are you trying to do with your an array of that size?
0
 

Author Comment

by:brucegm
ID: 11892949
I'm getting a few hundred rows of data (all 28 columns) and need to order them according to three of the columns and then generate an ordered XML output for import into a different application. The client won't actually see any of this, its all serverside.

0
 

Expert Comment

by:minucy
ID: 11893990
What you mean by " according to three of the columns "? Can you provide a short example of what you want to achieve?
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 11894582
In this case, why you dont get from database in order and then export directly the recordset to xml? I think this the best way.

Regards,

Walter.
0
 
LVL 4

Expert Comment

by:jcrumble
ID: 11894615
Is this a SQL based application?  If so you might try posting back to the same page with variable indicating how you wan the output sorted and regenerate your array based on an order by created when you have the columns you want to sort by (ie select ... order by parm1, parm2, parm3).  You can find many examples of this type of coding on various sites when reordering columns in html table like reports when you click on the column title.  

Please provide as mush detail as possible and more of an explaination of what your doing with the array.  Understanding that your going to XML, I still don't understand the purpose behind the array.  Being all server-side is the order you want consistent or will it be changed dynamically?  What is actually displayed to the client if not the information you are retrieving and how are they actually interacting with this ASP page to produce the array?

Any info you can provide would be great.

Thanks,
Jeff
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 5

Expert Comment

by:webtrans
ID: 11896115
what about u store the data in a tmp table and then delete the info in it?
0
 
LVL 3

Accepted Solution

by:
passmark earned 250 total points
ID: 11897474
ASP doesn't have a sort function for arrays built in (and how stupid is that!). Here is an example sort in ASP.

Sub ShellSort(array)
    last = UBound(array, 2)
    first = LBound(array, 2)
    num = last - first + 1
    ' find the best value for distance
    do
        distance = distance * 3 + 1
    loop until (distance > num)
    do
        distance = distance \ 3
        for index = (distance + first) to last
            value = array(1, index)
            value0 = array(0, index)
            value2 = array(2, index)
            value3 = array(3, index)
            value4 = array(4, index)
            value5 = array(5, index)
            index2 = index
            do while (index2 - distance => first)
                if (array(2, index2 - distance) > value2) then
                    exit do
                end if
                if (array(2, index2 - distance) = value2) then
                    if (array(1, index2 - distance) >= value) then
                        exit do
                    end if
                end if
                array(0, index2) = array(0, index2 - distance)
                array(1, index2) = array(1, index2 - distance)
                array(2, index2) = array(2, index2 - distance)
                array(3, index2) = array(3, index2 - distance)
                array(4, index2) = array(4, index2 - distance)
                array(5, index2) = array(5, index2 - distance)
                index2 = index2 - distance
            loop
            array(1, index2) = value
            array(0, index2) = value0
            array(2, index2) = value2
            array(3, index2) = value3
            array(4, index2) = value4
            array(5, index2) = value5
        next
    loop until distance = 1
End Sub

This is (obviously) a non-recursive shell sort of a two dimension array with 5 columns and unlimited rows, and it does work.

IMHO: ASP is a terrible language. If you can switch to another language (SQL, PHP, .NET, etc..) it would be better.

David
0
 

Author Comment

by:brucegm
ID: 11899813
Thanks Passmark. I'll try out this code and see if it works for me. Agreed on the ASP front though - it's ridiculous that there is no sort function. If i could use another language I would, but we are using cobol to extract the data off mpe and its being returned to me totally unsorted. Not ideal, but I'll try and get something to work.

thanks
0
 
LVL 4

Expert Comment

by:sgalzin
ID: 11911059
Hi,

I believe passmark is right about changing languages : I'm new to PHP but when reading the manual I saw there is a function called array_multisort which seems to do exactly what you want ! So maybe changing the server-side scripting engine from ASP to PHP would help ...

Stephane.
0
 
LVL 4

Assisted Solution

by:willcode4coffee
willcode4coffee earned 250 total points
ID: 12202308
Here is an article talking about sorting multi-dimensional arrays in .Net:

http://www.devx.com/dotnet/Article/21089/1954?pf=true


Hope this is what you are looking for.

They also have sampe code for download.

M@
0
 
LVL 3

Expert Comment

by:passmark
ID: 12391406
IMHO, a valid answer with source code was provided.

David
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now