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.
May 2, 2010, 5:13 AM
Veteran / Moderator (18441 posts)
May 2, 2010, 5:13 AM
Post #2 of 6
Views: 4227
Hi,
Something like this should work:
get_unique_cities_for_links
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:
<%loop city_loop%>
<%city_val%><br />
<%endif%>
Untested, but should work
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!
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
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!
May 2, 2010, 6:33 AM
Veteran / Moderator (18441 posts)
May 2, 2010, 6:33 AM
Post #4 of 6
Views: 4218
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!
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!
May 2, 2010, 7:11 AM
Veteran / Moderator (18441 posts)
May 2, 2010, 7:11 AM
Post #6 of 6
Views: 4195
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!