Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Extracting a record from multiple select?

Quote Reply
Extracting a record from multiple select?
hello!

if I have already done a select returning a list of records like...

Code:
my $asth = $adb->select( { question_id_fk => $input->{question_id} } ) || die $GT::SQL::error;

how can I then extract one record out $asth that has answer_id = $input->{answer_id}?

thanks

r
Quote Reply
Re: [ryel01] Extracting a record from multiple select? In reply to
You should be able to use;

Code:
my $value = $adb->select( ['FIELDTOGET'], { question_id_fk => $input->{question_id} } )->fetchrow;

...or;

Code:
my $asth = $adb->select( { question_id_fk => $input->{question_id} } )->fetchrow_hashref;

...or even;

Code:
my @vals = $adb->select( ['FIELD1','FIELD2','FIELD3'],{ question_id_fk => $input->{question_id} } )->fetchrow_array;

Hope that helps.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Extracting a record from multiple select? In reply to
not short on answers are ya! Wink

is there any way to extract it from the existing "$asth" result?

r
Quote Reply
Re: [ryel01] Extracting a record from multiple select? In reply to
LOL!

Quote:
is there any way to extract it from the existing "$asth" result?

Not sure what you mean?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Extracting a record from multiple select? In reply to
Don't worry... I'm confusing myself... Sly

I've already done a select which grabs a list of records...

Code:
my $RESULT = $adb->select( { question_id_fk => $input->{question_id} } ) || die $GT::SQL::error;

which I'm using in a loop.

But now I also want to extract one record out of $RESULT which has answer_id = $input->{answer_id}.

hehehe...

r
Quote Reply
Re: [ryel01] Extracting a record from multiple select? In reply to
heheh.

You should be able to do it with;

Code:
my $record = $adb->select( { question_id_fk => $input->{question_id} } )->fetchrow_hashref || die "No record found";

You can then access the values wit $record->{FIELDNAME}

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Extracting a record from multiple select? In reply to
yeah thanks for that.

I was trying to be tricky and do it without doing another select to the database... but I guess "who really cares" if you do another select!
just being anal...

r
Quote Reply
Re: [ryel01] Extracting a record from multiple select? In reply to
You could do it with one select (although it would be harder);

Code:
my $result_hash;

my $sth = YOUR SELECT STUFF HERE (normal, multi record);
while (my $hit = $sth->fetchrow_hashref) {

if ($hit->{question_id_fk} == $input->{question_id}) {
$results_hash = $hit;
}

# now do your other stuff...

}

Then, $results_hash *should* hold the value of the result in question :)

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Extracting a record from multiple select? In reply to
cool! - that'll do what I'm after!

I haven't got the hang of fetchrow_hashref and fetchall_hashref - do you know if there is any info on them in the pm files anywhere? I couldn't find it anywhere when I looked.

regan
Quote Reply
Re: [ryel01] Extracting a record from multiple select? In reply to
Cool :)

Quote:
I haven't got the hang of fetchrow_hashref and fetchall_hashref - do you know if there is any info on them in the pm files anywhere? I couldn't find it anywhere when I looked.

Afraid not. Your best bet is the forum (its boring, but there is a wealth of information, as I'm sure you know =)).

I have to admit.. I've never even had to use fetchall_hashref ... you sure its even a function? Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Extracting a record from multiple select? In reply to
In Reply To:
I have to admit.. I've never even had to use fetchall_hashref ... you sure its even a function? Wink


LOL!

Yeah that one's a new one - I'm not sure it's been added to the manual pages I was referring to yet though... Wink

r

(or any of the pm files...)

EDIT: Actually I just realised I'm using "fetchall_hashref" so it does exist!

Last edited by:

ryel01: Aug 16, 2004, 2:12 AM
Quote Reply
Re: [ryel01] Extracting a record from multiple select? In reply to
Quote:
Yeah that one's a new one - I'm not sure it's been added to the manual pages I was referring to yet though...

LMAO! That just cheered my day up Laugh

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!