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 (17366 posts)
May 2, 2010, 5:13 AM
Post #2 of 6
Views: 557
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
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
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
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
May 2, 2010, 6:33 AM
Veteran / Moderator (17366 posts)
May 2, 2010, 6:33 AM
Post #4 of 6
Views: 557
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
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
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
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
May 2, 2010, 7:11 AM
Veteran / Moderator (17366 posts)
May 2, 2010, 7:11 AM
Post #6 of 6
Views: 545
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
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates

