Gossamer Forum
Home : Products : Links 2.0 : Customization :

Re: Sort by date

Quote Reply
Re: Sort by date In reply to
grrrr...

Any ideas what i'm doing wrong ?

Code:
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 alphabetically. 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 {
&date_to_unix ($sortby{$b}) <=> &date_to_unix ($sortby{$a})
} (keys %sortby)) {

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

Code:
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 175, 1, 'http://', '^http|news|mailto|ftp'],
Width => [3, 'numer', 10, 10, 1, '', ''],
Height => [4, 'numer', 10, 10, 1, '', ''],
Filesize => [5, 'numer', 10, 10, 1, '', ''],
Dateline => [6, 'alpha', 40, 75, 1, '', ''],
Date => [7, 'date', 15, 15, 1, \&get_date, ''],
Category => [8, 'alpha', 0, 150, 1, '', ''],
AltCategories => [9, 'alpha', 0, 1000, 0, '', ''],
Description => [10, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [11, 'alpha', 40, 75, 0, '', ''],
'Contact Email' => [12, 'alpha', 40, 75, 0, '', '.+@.+\..+'],
Hits => [13, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [14, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [15, 'alpha', 0, 5, 0, 'No', ''],
isPick => [16, 'alpha', 0, 5, 0, 'No', ''],
Votes => [17, 'numer', 10, 10, 1, '0', '^\d+$'],
Rating => [18, 'numer', 10, 10, 1, '0', '^[\d\.]+$'],
ReceiveMail => [19, 'alpha', 10, 10, 1, 'Yes', 'No|Yes']
);

Code:
# Field number to sort links by:
$db_sort_links = 7;

Code:
2|#95 - Not On ABC, Please|http://216.55.29.184/images/cartoons/cart/rdameric.jpg|600|363|82|Road America '99|12-Nov-1999|Carlos_Carneiro/CART&#0124; &#0124;CART TV coverage cancelled to make way for poxt golf game!|Carlos|Suzzcar@aol.com|13|No|Yes|No|0|0|Yes
3|#91 - Colombian Donuts|http://216.55.29.184/images/cartoons/cart/juandnut.jpg|600|258|50|Portland '99|12-Nov-1999|Carlos_Carneiro/CART&#0124; &#0124;|Carlos Carneiro|Suzzcar@aol.com|3|No|No|No|0|0|Yes
4|#108 - Safe Bet|http://216.55.29.184/images/cartoons/f1/safebet.jpg|650|427|113|Japanese GP '99|13-Nov-1999|Carlos_Carneiro/F1&#0124; &#0124;|Carlos Carneiro|Suzzcar@aol.com|2|Yes|No|No|0|0|Yes
5|Brawnimoto-San|http://www.soft-toon.demon.co.uk/f199/gp9918.jpg|700|526|58|Malaysian GP '99|28-Oct-1999|Gurmit_Flora&#0124; &#0124;|Gurmit Flora|gurmit@soft-toon.demon.co.uk|4|No|No|No|0|0|Yes
6|Marketing Opportunities|http://www.soft-toon.demon.co.uk/f199/gp9901.jpg|650|434|82|Pre Season '99|14-Jan-1999|Gurmit_Flora&#0124; &#0124;|Gurmit Flora|gurmit@soft-toon.demon.co.uk|1|No|No|No|0|0|Yes
7|From Clothes To Cars|http://www.soft-toon.demon.co.uk/f199/gp9902.jpg|672|463|74|Pre Season '99|31-Jan-1999|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
8|Top secret developments at McLaren|http://www.soft-toon.demon.co.uk/f199/gp9903.jpg|450|624|70|Pre Season '99|18-Feb-1999|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
9|Australian GP|http://www.soft-toon.demon.co.uk/f199/bf0199.gif|629|536|49|Australian GP '99|12-Mar-1999|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|1|No|No|No|0|0|Yes
10|Flexible Wings|http://www.soft-toon.demon.co.uk/f199/gp9904.jpg|700|492|70|Australian GP '99|23-Mar-1999|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|1|No|No|No|0|0|Yes
11|Brazilian GP|http://www.soft-toon.demon.co.uk/f199/bf0299.gif|600|476|39|Brazilian GP '99|15-Apr-1999|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
12|Looking for San Marino|http://www.soft-toon.demon.co.uk/f199/gp9905.jpg|650|446|59|San Marino GP '99|29-Apr-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
13|San Marino GP|http://www.soft-toon.demon.co.uk/f199/bf0399.gif|400|544|30|San Marino GP '99|6-May-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
14|Don't Be Cruel|http://www.soft-toon.demon.co.uk/f199/gp9906.jpg|407|600|36|San Marino GP '99|11-May-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
15|Monaco GP|http://www.soft-toon.demon.co.uk/f199/bf0499.gif|400|547|53|Monaco GP '99|20-May-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
16|Wowie!|http://www.soft-toon.demon.co.uk/f199/gp9907.jpg|410|574|42|Monaco GP '99|26-May-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
17|Spanish GP|http://www.soft-toon.demon.co.uk/f199/bf0599.gif|650|484|42|Spanish GP '99|5-Jun-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
18|Montreal Airport GP|http://www.soft-toon.demon.co.uk/f199/gp9908.jpg|650|484|56|Canadian GP '99|10-Jun-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
19|Canadian GP|http://www.soft-toon.demon.co.uk/f199/bf0699.gif|700|484|39|Canadian GP '99|18-Jun-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
20|Aero mods for Prost|http://www.soft-toon.demon.co.uk/f199/gp9910.jpg|675|477|60|French GP '99|24-Jun-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
21|French GP|http://www.soft-toon.demon.co.uk/f199/bf0799.gif|400|562|31|French GP '99|1-Jul-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
22|Ultimate Jordan Babe|http://www.soft-toon.demon.co.uk/f199/gp9909.jpg|425|612|31|French GP '99|8-Jul-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes
23|British GP|http://www.soft-toon.demon.co.uk/f199/bf0899.gif|450|582|38|British GP '99|14-Jul-99|Gurmit_Flora&#0124; &#0124;&#0124; &#0124;|0|No|No|No|0|0|Yes

That little lot spews out: http://www.ten-tenths.com/toons/Gurmit_Flora/ which, as you will notice from the date which I added to aid bedugging, doesn't work out quite right! I got this mod to work on our Parc Ferme magazine, so I know it works - it's just me staring right past the obvious!

------------------
Craig Antill
10 Tenths Motorsport - www.Ten-Tenths.com/links/
Parc Ferme Magazine - www.Ten-Tenths.com/Parc_Ferme/
THE Directory - www.gardenbuildings.com/

Subject Author Views Date
Thread Sort by date Ryan 3921 Jan 24, 1999, 3:56 AM
Post Re: Sort by date
Alex 3822 Jan 27, 1999, 8:17 PM
Post Re: Sort by date
Ryan 3822 Jan 27, 1999, 8:54 PM
Post Re: Sort by date
Asterisk 3818 Jan 28, 1999, 9:37 AM
Post Re: Sort by date
Ryan 3814 Jan 28, 1999, 9:49 AM
Post Re: Sort by date
gotze 3812 Jun 9, 1999, 11:39 AM
Post Re: Sort by date
Craig A 3816 Nov 20, 1999, 12:44 PM
Post Re: Sort by date
Craig A 3813 Nov 21, 1999, 7:11 AM
Post Re: Sort by date
Craig A 3847 Nov 24, 1999, 10:13 AM
Post Re: Sort by date
Craig A 3810 Nov 26, 1999, 11:36 PM
Post Re: Sort by date
Eliot 3810 Feb 8, 2000, 6:58 PM