logic for sorting

Posted on 2003-03-25
Medium Priority
Last Modified: 2010-03-05

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
Question by:inudaci
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

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.

Author Comment

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.
LVL 20

Accepted Solution

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.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

801 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