Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Dropdown list of links

Quote Reply
Dropdown list of links
Apologies if this has already posted - I did think I'd posted it yesterday but it seems to have got lost.

I've written a global to show all the links in a category and its first level subcategories in a dropdown list:

sub {
my $tags = shift;
my $cat_id = $tags->{'ID'};
my $name = $tags->{'Name'};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ("ORDER BY $CFG->{build_sort_order_category}");
my $sth = $link_db->select ( { CategoryID => $cat_id, isValidated => 'Yes' });

my $output = qq~
<select name="Url" onChange="goUrl(this)" size=1 WIDTH="250" STYLE="width:250px">
<option VALUE=" ">Links in $name
<option VALUE=" ">----------------
~;
while (my $link = $sth->fetchrow_hashref) {
$output .= qq~
<option value="$CFG->{db_cgi_url}/detail.cgi?ID=$link->{'ID'}">$link->{'Title'}
~;
}

my $cat_db = $DB->table('Category');
my $sth2 = $cat_db->select ( ['ID'],{ FatherID => $cat_id });

while (my $child_id = $sth2->fetchrow_array){
my $sth3 = $link_db->select ( { CategoryID => $child_id, isValidated => 'Yes' });
while (my $link2 = $sth3->fetchrow_hashref) {
$output .= qq~
<option value="$CFG->{db_cgi_url}/detail.cgi?ID=$link2->{'ID'}">$link2->{'Title'}
~;
}
}

$output .= qq~
</select>
<noscript>
<input TYPE="submit" VALUE="Go">
</noscript>
~;

return $output;
}



This works but I don't think its very efficient. I was wondering whether there is any way of pulling all the links from the database at once, i.e. can I select links in this category AND links in each subcategory with one request? Thanks for any comments.

Laura.