Gossamer Forum
Quote Reply
Category Drop Down Field
Hi champs,

I have the folowing global, which I assume originated from andy or laura. I want to add the possiblity to pass a parameter of the top category, so that I can call the global like <%global('1')%>, whereas 1 stands for the top category that will be included in the selection of the categories. For example, if I have

catid 1 = ABC
catid 2 = CDE

if I use the global <%global('1')%>, only the caid 1 and all the subcategories should be shown in the drop down field.

sub {
my $show_count = $_[0];
my $category;
my $db = $DB->table('Category') || return $GT::SQL::error;
$db->select_options('ORDER BY Full_Name') || return $GT::SQL::error;
my $sth = $db->select( ['ID','Full_Name','Number_of_Links'] ) || return $GT::SQL::error;

my $back;

while (my ($id,$full_name,$numberoflinks) = $sth->fetchrow_array) {

my $full_name2;
my @cut = split /\//, $full_name;
for (my $i=0; $i < $#cut; $i++) {

$full_name2 .= "&nbsp;&nbsp;";


$full_name2 .= $cut[$#cut];
if ($show_count) {
$full_name2 .= " ($numberoflinks)";

$back .= "<option value=\"$id\">$full_name2</option>";


my $send_back = qq|<select size="1" name="catid"><option value=""<------</option>$back</select>|;

return $send_back;


Quote Reply
Re: [vacationrentals] Category Drop Down Field In reply to
Wrong forum Wink (I've moved it for you)

A quick answer, would be something like this;

my $cond = GT::SQL::Condition->new('Full_Name','LIKE','CategoryName%');
my $sth = $db->select( ['ID','Full_Name','Number_of_Links'], $cond )
|| return $GT::SQL::error;

...which should then grab the category in question, and its sub-categories.

You would also modify it a little bit more... by adding;

my $category_name = $_[1];

... right below;

my $show_count = $_[0];

Then, you will need to use;

my $cond = GT::SQL::Condition->new('Full_Name','LIKE',"$category_name%");
my $sth = $db->select( ['ID','Full_Name','Number_of_Links'], $cond )
|| return $GT::SQL::error;

.. and then call with;

<%global('1','Category Name')%>

Not tested.. but should work / get you on the right tracks :)

Hope that helps.


Andy (mod)
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] Category Drop Down Field In reply to
Cheers for that! Works.