I want to sort by 'Sort', 'isNew', 'Rating', 'Votes', 'Title'
after searching this forum for 3 hours:
added to links.def:
...
Sort => [14, 'alpha', 2, 2, 1, 'n', '']
...
$db_sort = 14;
...
$db_sort_links = 1; (left default)
added new field to all records.
changed in db_util.pl:
*****************************
sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort alphabetically field "Sort" and then "____". By modifying
# the sort function below, you can sort the links however you like. Just change sort to "a" for the links you want
# first (ie. premium listing) and to "n" for normal links
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_sort + $offset, $db_isnew + $offset, $db_rating + $offset, $db_votes + $offset, $db_title + $offset]);
}
foreach $hit (sort {
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
****************************
It puts records with 'Sort'='a' before 'Sort'='n', as I need it.
But the rest of sorting is not working. Ratings sorts backwards and, i think, i have to tell the script to sort 'Rating' and 'Votes' as numeric not text fields.
What should I do? Please help.
Anton Pachkine [ anton@27stars.com ]
www.OnlineBusinessDirectory.org
- Built by People for People
================================================
PS: Have a great service, article, eBook or eZine
for online entrepreneurs?
Register it for hundreds of people to find!
http://www.OnlineBusinessDirectory.org
================================================
after searching this forum for 3 hours:
added to links.def:
...
Sort => [14, 'alpha', 2, 2, 1, 'n', '']
...
$db_sort = 14;
...
$db_sort_links = 1; (left default)
added new field to all records.
changed in db_util.pl:
*****************************
sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort alphabetically field "Sort" and then "____". By modifying
# the sort function below, you can sort the links however you like. Just change sort to "a" for the links you want
# first (ie. premium listing) and to "n" for normal links
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_sort + $offset, $db_isnew + $offset, $db_rating + $offset, $db_votes + $offset, $db_title + $offset]);
}
foreach $hit (sort {
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
****************************
It puts records with 'Sort'='a' before 'Sort'='n', as I need it.
But the rest of sorting is not working. Ratings sorts backwards and, i think, i have to tell the script to sort 'Rating' and 'Votes' as numeric not text fields.
What should I do? Please help.
Anton Pachkine [ anton@27stars.com ]
www.OnlineBusinessDirectory.org
- Built by People for People
================================================
PS: Have a great service, article, eBook or eZine
for online entrepreneurs?
Register it for hundreds of people to find!
http://www.OnlineBusinessDirectory.org
================================================