Gossamer Forum
Quote Reply
Category list global
Hi

i am trying to make a global that will return a list of the categories and their IDs in a select field







sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options("ORDER BY Full_Name");
my @root_cats = $cat_db->select (['Full_Name'], ['ID'])->fetchall_list;
my $output;
foreach my $cat (@cats) {
my $ID = $cat_db->as_id($cat);
$output .= qq~<option value="$ID">$cat~;
}
return $output;
}

The above global returns errors and suggestions to fix it..
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Category list global In reply to
Try:

Code:
sub {
my ($db,$sth,$row);
my ($output) = qq|<select name="Category">|;

$db = $DB->table('Category');
$db->select_options("ORDER BY Full_Name");
$sth = $db->select( ['ID','Full_Name'] )->fetchrow_hashref;

while ($row = $sth->fetchrow_hashref) {
$output .= qq|<option value="$row->{ID}">$row->{Full_Name}\n|;
}

$output .= qq|</select>|;

return $output;

}
Quote Reply
Re: [Paul] Category list global In reply to
Hi Paul

I am getting:

Can't call method "fetchrow_hashref" on unblessed reference at (eval 10) line 9.


Any suggestions?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Category list global In reply to
Hi,

>
$sth = $db->select( ['ID','Full_Name'] )->fetchrow_hashref;
>

Try this may work

$sth = $db->select( ['ID','Full_Name'] );

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [katabd] Category list global In reply to
Whoops my bad. I forgot to chop off fetchrow_hashref.
Quote Reply
Re: [tandat] Category list global In reply to
Hi

Thank you both..

the change does not fix the problem (actually does0 but still the ID is not being generated..

i change the layout so I do not need the ID anymore..

Thanks again for trying
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Category list global In reply to
Does it build the list?

How is the ID being generated?...Im not sure what you mean.
Quote Reply
Re: [Paul] Category list global In reply to
Hi

I am trying to build a category list the same way add.cgi generates the category list when category is on..

But I want that category list to be through globals.

It will return each category (full name and ID).
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Category list global In reply to
Take a look at Links::User::Add and scroll to the bottom. The category_list routine for add.cgi is there. You may be able to get some hints.
Quote Reply
Re: [Paul] Category list global In reply to
Thanks paul
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory