Gossamer Forum
Home : Products : Gossamer Links : Discussions :

lookup in new table with a global

Quote Reply
lookup in new table with a global
Hi,

Well i having a little problem with making a global for this;

I have one new table called Local with fields id,area and place.

I wanna do a search on field place (and a search on "ho" is a place that contains "ho", so houston if a vallid place)

if results = 0 return page "place not found, how sad".
if results = 1 return page "place found display a area page".
if results > 1 return page "all place's on one page to select one place".

I quess u have to make a array (fetch it) and a result counter ....

Hope someone can help me on the way...

Allready thanks.

Regards Startpoint...

BTW: i used other field names and a table name so u understand it better:)

Quote Reply
Re: [startpoint] lookup in new table with a global In reply to
Hi,

Something like:

Code:
Place_Lookup => sub {
my $tags = shift;
my $table = DB->table('Local');
my $condition = GT::SQL::Condition->new('place', 'LIKE', "%$tags->{place}%");
my $sth = $table->select ($condition);
my @loop;
my $count;
while (my $hash = $sth->fetchrow_hashref) {
push @loop, $hash;
$count++;
}
return { Place_Count => $count, Place_Loop => \@loop };
}

And then you would do:

<%Place_Lookup%>
Your search returned: <%Place_Count%>. Here they are:
<%loop Place_Loop%>
<%place%>, <%area%>, <%id%>.
<%endloop%>

Hope that helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] lookup in new table with a global In reply to
Hi Alex,

Thanks that helped me a lot on the way to a solution.

Regards startpoint..