Gossamer Forum
Quote Reply
Grab column form ID's
How can I send a list if ID's like 345,4545,343,2,34,456,997 and grab from these ID's a specific column like City and get a list of all the city in this ID's.
Quote Reply
Re: [nir] Grab column form ID's In reply to
Hi,

Something like this should work:

get_unique_cities_for_links
Code:
sub {
my $ids;
my $field = "City";
foreach (split /,/, $_[0]) {
push @$ids, $_;
}

my $sth = $DB->table('Links')->select( ["DISTINCT($field)"], GT::SQL::Condition->new('ID','IN',$ids) ) || die $GT::SQL::error;
my @cities;
while (my $city = $sth->fetchrow) {
push @cities, { city_val => $city };
}

return { city_loop => \@loop }

}

..and call with:

Code:
<%get_unique_cities_for_links('1234,3234,243,6546,44365,434'')%>
<%loop city_loop%>
<%city_val%><br />
<%endif%>

Untested, but should work Smile

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] Grab column form ID's In reply to
Thanks Andy,Smile
There is a small error if in all the ID's there is value in the City column it is working good, but if there are ID's without value in the City columns the list that I get is wrong, it delete some of the City and give a small list.
Quote Reply
Re: [nir] Grab column form ID's In reply to
Hi,

Are you saying there is a problem when one of the ID's doesn't have a value in the "City" field? If so, try this:

my $sth = $DB->table('Links')->select( ["DISTINCT($field)"], GT::SQL::Condition->new('ID','IN',$ids,"LENGTH($field)",'>','0') ) || die $GT::SQL::error;

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] Grab column form ID's In reply to
Many Thanks,
Just one small- is there a way to return the order of the loop by the top City (the city that have the most ID's to the lower.)
Quote Reply
Re: [nir] Grab column form ID's In reply to
Quote:
Just one small- is there a way to return the order of the loop by the top City (the city that have the most ID's to the lower.)

Not that I know of, sorry.

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!