Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

select 2 fields from 2 db and sort-help!

Quote Reply
select 2 fields from 2 db and sort-help!
For the last two days I have been trying to do two distinct selects from 2 distinct tables on fields that are named the same, then combine them into 1 array and sort it.

These are my queries
$sth = $LINKDB->prepare ("SELECT Series,ID FROM Links where CategoryID = '18' ORDER BY Series");
$adt = $LINKDB->prepare ("SELECT a.Series,c.ID FROM Links as c, Links_Additional_Dates as a where (c.ID=a.ID) and c.Series > '2001-04-31' and c.Add_Date > '2001-04-01' ORDER BY a.Series");

Links contains 31 fields or so.
Links_Additional_Dates contains ID and Series - ID is the same ID as found in Links


Then I read them into an array like this

while ($event = $sth->fetchrow_hashref) {
push @$events, $event;
}
while ($event = $adt->fetchrow_hashref) {
push @$events, $event;
}

Now I want to resort the array according to the dates as found in the Series column but I can't figure out how to sort it with something like:
foreach my $tmp(sort @$events) {.....

I've tried a hundred variations of sort(I'm not kidding) but can't seem to get it to sort by anything other than the address which looks like this:
HASH(0x827c974)

Once I step through the array I can access both tmp->{Series} and tmp->{ID}

I'm either reading @$events wrong, or I am doing something wrong in the sort. I've tried this:
foreach my $tmp (sort { ($events->{$a}->{Series} <=> $events->{$b}->{Series}) } @events) {...

and that just tells me NOT a HASHREF.

Does anyone have an idea how to sort that array on something other than the address or have a suggestion on
how to read into those two fields into a hash properly so that I can sort by the Series which are actually dates?

Thanks - you are a hero.

Kyle
Subject Author Views Date
Thread select 2 fields from 2 db and sort-help! klangan 5011 May 1, 2001, 10:39 PM
Thread Re: select 2 fields from 2 db and sort-help!
Stealth 4911 May 2, 2001, 9:07 AM
Thread Re: select 2 fields from 2 db and sort-help!
klangan 4944 May 2, 2001, 9:23 AM
Thread Re: select 2 fields from 2 db and sort-help!
Stealth 4881 May 2, 2001, 11:01 AM
Post Re: select 2 fields from 2 db and sort-help!
klangan 4882 May 2, 2001, 11:12 AM
Thread Re: select 2 fields from 2 db and sort-help!
Alex 4884 May 2, 2001, 3:04 PM
Thread Re: select 2 fields from 2 db and sort-help!
klangan 4890 May 2, 2001, 3:18 PM
Post Re: select 2 fields from 2 db and sort-help!
Alex 4868 May 2, 2001, 3:31 PM