Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

logic for sorting

Posted on 2003-03-25
3
Medium Priority
?
188 Views
Last Modified: 2010-03-05
hi,

i would like to know the logic for a sorting system identical to the one you have in window, when in a folder with the detailed view.

when clicking a field header it sorts that field. but when u click it twice it reverses it, how can i get this logic to work?

actually if you could just provide me with the if statement in a way similar like following code, what am i missing, do i need these variables at all, is there a cleaner way?

if ($sortSentValue != $sortSentValueOld && reverseSentOld == reverseSent) {$reverseSet = 0;}
else {$reverseSet = 1;}

all i need to get is the reverseSet variable in a similar way
0
Comment
Question by:inudaci
3 Comments
 
LVL 1

Expert Comment

by:zmagyar
ID: 8206536
Perl has inbuilt sort support for arrays. Isn't it suitable for you? E.g. if you have @array containing random values then

@sorted = sort {$a <=> $b} @array;

would result a sorted list while

@reverse = sort {$b <=> $a} @array;

results reserved sort order.
0
 

Author Comment

by:inudaci
ID: 8206594
thanks, yes, i am using something like those syntaxes, but, it's kind of the logic around that which im having some trouble with.
0
 
LVL 20

Accepted Solution

by:
jmcg earned 80 total points
ID: 8206659
You have parameters attached to the action URL for the field header buttons, right? Since you're dynamically generating the rest of the table, you can generate this URL. It can have a parameter like "ascending=1". When you regenerate the page with the reverse sort, you toggle the value of the variable

$ascending ^= 1; # exclusive OR

before marshalling it into the action URL.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

580 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