Hi,
Took a little while to do, but here you go:
load_links
my ($limit,$sort_order,$cat_id) = (shift,shift,shift);
my @queries = @_;
$sort_order ||= "Title ASC";
my $tbl = $DB->table('Links');
if ($limit) {
$tbl->select_options(qq|ORDER BY $sort_order LIMIT $limit|);
} else {
$tbl->select_options(qq|ORDER BY $sort_order|);
}
my $cond = new GT::SQL::Condition;
foreach (@queries) {
my ($field,$operator,$val) = split /::/;
$cond->add($field,$operator,$val);
}
$cond->bool("AND");
my $sth = $tbl->select( $cond, { 'CatLinks.CategoryID' => $cat_id } ) || die $GT::SQL::error;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
$hit = Links::SiteHTML::tags('link', $hit);
push @loop, $hit;
}
return { cond_loop_link => \@loop }
}
Call with:
...so a "proper" example:
..which would get links from category ID 123, sorted by Title ASC and limit it to 10. It would also look for:
Foo LIKE "%bar%"
If you are calling this from inside a category that you wanna get the results from, you can use $category_id in the place of 123.
To show the results you just do:
<%include link.html%>
<%endloop%>
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!
Took a little while to do, but here you go:
load_links
Code:
sub { my ($limit,$sort_order,$cat_id) = (shift,shift,shift);
my @queries = @_;
$sort_order ||= "Title ASC";
my $tbl = $DB->table('Links');
if ($limit) {
$tbl->select_options(qq|ORDER BY $sort_order LIMIT $limit|);
} else {
$tbl->select_options(qq|ORDER BY $sort_order|);
}
my $cond = new GT::SQL::Condition;
foreach (@queries) {
my ($field,$operator,$val) = split /::/;
$cond->add($field,$operator,$val);
}
$cond->bool("AND");
my $sth = $tbl->select( $cond, { 'CatLinks.CategoryID' => $cat_id } ) || die $GT::SQL::error;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
$hit = Links::SiteHTML::tags('link', $hit);
push @loop, $hit;
}
return { cond_loop_link => \@loop }
}
Call with:
Code:
<%load_links(LIMIT,'SORT ORDER',CATEGORY_ID,'isValidated::=::Yes','Foo::LIKE::%bar%')%>...so a "proper" example:
Code:
<%load_links(10,'Title ASC',123,'isValidated::=::Yes','Foo::LIKE::%bar%')%>..which would get links from category ID 123, sorted by Title ASC and limit it to 10. It would also look for:
Code:
isValidated => Yes Foo LIKE "%bar%"
If you are calling this from inside a category that you wanna get the results from, you can use $category_id in the place of 123.
To show the results you just do:
Code:
<%loop cond_loop_link%> <%include link.html%>
<%endloop%>
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!