#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    12
    Rep Power
    0
    I'm having trouble with sorting an associative array by certain parts of it's value. The array's keys are numbers starting at one and going up to whatever the amount of read results is. The values are a number of different things describing a part. The value needs to be parsed to get each particular variable. I want the user to be able to select part# or cost(or any other variable) and have it sort the results by that. Right now I'm breaking it down by putting the key into a new array with it's new value being what the user chose to sort it by. Because associative arrays don't stay sorted I am putting what should be the keys of the sorted values into a new array(maybe I just have too many arrays) (: This array is then used as the keys to the original array to output all the results in the sorted order.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    foreach $part (keys(%results)) {
    ($invdate,$invnum,$vendor,$lspartnum,$parttype,$manufname,$modelnum,
    $serialnum,$desc,$cost,$price) = split(/:/, $results{$part});
    if ($sortby eq "pnum") {
    $sortingresults{$part} = $lspartnum;
    }
    if ($sortby eq "cost") {
    $sortingresults{$part} = $cost;
    }
    #etc.
    }

    for (sort {$a <=> $b;} (values (%sortingresults))) {
    @resultsarray = (keys (%sortingresults));
    }

    foreach $part (@resultsarray) {
    ($invdate,$invnum,$vendor,$lspartnum,$parttype,$manufname,$modelnum,
    $serialnum,$desc,$cost,$price) = split(/:/, $results{$part});
    &DisplayTable;
    }
    [/code]

    I'm sure I'm doing something terribly wrong, or backwards, I can get the output, but it's not in a sorted order. Maybe I'm making it to complicated?
    Any suggestions would be greatly appreciated. Thanks in advance.

    [This message has been edited by Obsidian11 (edited August 07, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    Eeek, that's a big thing you're trying to accomplish here. I'd just use an SQL (mysql) server and have it do all the sorting.

    I'm sure what you're trying to do can be done, but I can't think of a quick solution off the top of my head.
  4. #3
  5. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    freeebsd is just an archive of links to old threads .
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    12
    Rep Power
    0
    Hahaha, yes I've noticed (:

    Thank you both for you help, I'll take a look at the old thread and see if it will help me!

IMN logo majestic logo threadwatch logo seochat tools logo