Gossamer Forum
Quote Reply
I have been on this forum for 3 hours with no luck. The only things I find are links to NONEXISTANT mods.

The code that obviously should work DOES NOT WORK.

I have added new fields to my database. I have a NEW FIELD called "SCORE" this is NUMERIC.

The ONLY thing I want to do is FIRST sort by SCORE and within SCORE I want to sort by RATING.

Now... I DO have my SCORE Sorted.

If an item has a RATING it gets pushed to the top above records with a higher SCORE (i do not want this.)

On top of that the RATING is fubar. It gives me a sort of 3,2,1,4 instead of 4,3,2,1.

If a record has a RATING of ZERO it seems to get skipped.

I have tried 50 variations of code.

So to make it all clear.

SCORE = position 14 and DID change $db_sort_links = 14;
I HAVE changed db.utils.pl a 100 times.

Here is what I have currently:

sub build_sorthit {
# --------------------------------------------------------
# My Crap that doesnt work
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby,%rating,%cost, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];

($unsorted[$db_cost + ($i * ($#db_cols+1))]) and ($cost{$i} = 1);
($unsorted[$db_rating + ($i * ($#db_cols+1))]) and ($rating{$i} = 1);
foreach $hit (sort {

($cost{$b} and !$cost{$a}) and return 1;
($cost{$a} and !$cost{$b}) and return -1;

($rating{$b} and !$rating{$a}) and return 1;
($rating{$a} and !$rating{$b}) and return -1;

($cost{$a} and $cost{$b}) and return $sortby{$b} <=> $sortby{$a};
($rating{$a} and $rating{$b}) and return $sortby{$b} <=> $sortby{$a};

return $sortby{$b} <=> $sortby{$a};

} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
return @sorted;

Again, I want to sort by SCORE 'then' RATING (if i have 3 records with the same SCORE they will be sorted by RATING)

Items with a ZERO Rating should not be skipped.

Please dont tell me this has been discussed before. I KNOW THIS. The code does not work, or the links to the ONLY PERSON who knows how to do this are dead.

(Oh its late has hell. Please treat SCORE and COST as the same variable)

Quote Reply
Re: SORTING! In reply to
Current info: http://www200.pair.com/ht1138/cgi-bin/links/pages/Cat1/
Admin: http://www200.pair.com/ht1138/cgi-bin/links/cgi-bin/admin/admin.cgi
feel free