Gossamer Forum
Home : Products : Links 2.0 : Customization :

Need a little help with a sort routine

Quote Reply
Need a little help with a sort routine
After reading this very helpful forum for quite some time, I have been able to apply or make some slight modification to most mods so they work to suit my needs. But now time has come to ask for a little help.

I want to sort my category pages so that:

Priority Links first in reverse order(Z-A for example)
New Links next
Then all the rest in random order

Presently I am using the following routine. It does New first than all the rest is random. I just can't figure out what to add/delete to get the Priority to the top(I don't care if the Priority Links are random or alphabetically sorted. In fact random would probably be best come to think about it.

sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort
# new links first, then cool links, then the rest randomly. By modifying
# the sort function below, you can sort the links however you like (by date,
# or random, etc.).
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, %iscool, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return (rand > 0.5) ? 1 : -1;
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
sub urlencode {


Any help would be much, much appreciated.
Thanks!
Quote Reply
Re: [EzRyder] Need a little help with a sort routine In reply to