Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Need Help - Main Categories Global

Quote Reply
Need Help - Main Categories Global
Hi I've searched around the forum and Resources for a global which will display only the main categories, couldn't find one. So i tried creating my own, I just need a little help with how the syntax works

Code:


sub {
my @cats = $DB->table('Category')->select( 'Name' )->where('FatherID = 0');
#
for (@cats) {
print "$_<br />\n";
}
}


I'm not exactly sure about the where('FatherID = 0') part. How does perl & SQL work? I'm only used to PHP & SQL
Quote Reply
Re: [kzap] Need Help - Main Categories Global In reply to
I would personally use something like this;

Code:
sub {

my $table = $DB->table('Category');
my $return_cats;

$table->select_options ('ORDER BY Name ASC');
my $sth = $table->select( { FatherID => '0' } );

while (my $hit = $sth->fetchrow_hashref) {
$return_cats .= $hit->{Name} . "<br />\n";
}

return $return_cats;

}

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!
Quote Reply
Re: [Andy] Need Help - Main Categories Global In reply to
how would you modify this to print out all the cat's recursively and to link them up with the appropriate URL's :)
Quote Reply
Re: [scorpioncapital] Need Help - Main Categories Global In reply to
Cats, and subcats?

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!
Quote Reply
Re: [Andy] Need Help - Main Categories Global In reply to
Thanks, now when I was trying to link them it just wouldn't work:

Code:


sub {

my $table = $DB->table('Category');

my $return_cats;



$table->select_options ('ORDER BY Name ASC');

my $sth = $table->select( { FatherID => '0' } );



while (my $hit = $sth->fetchrow_hashref) {

my $caturl = $hit->(Full_Name);

$return_cats .= "<a href=\"/" . as_url($caturl); . "/\">" . $hit->{Name} . "</a><br />\n";

}



return $return_cats;

}

Quote Reply
Re: [kzap] Need Help - Main Categories Global In reply to
You need to explain "didn't work" a bit more than that if you want us to help you ;)

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!
Quote Reply
Re: [scorpioncapital] Need Help - Main Categories Global In reply to
sure, let's say both...
Quote Reply
Re: [Andy] Need Help - Main Categories Global In reply to
Ok sorry, when I tried implement my linking method, using as_url($caturl)

it says the globalname didnt compile when i view it on my pages
Quote Reply
Re: [kzap] Need Help - Main Categories Global In reply to
You need to use $table->as_url($var).

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!
Quote Reply
Re: [scorpioncapital] Need Help - Main Categories Global In reply to
In Reply To:
sure, let's say both...

Simple, give this a go;

Code:
sub {

my $table = $DB->table('Category');
my $return_cats;

$table->select_options ('ORDER BY Full_Name ASC');
my $sth = $table->select();

while (my $hit = $sth->fetchrow_hashref) {
$return_cats .= $hit->{Full_Name} . "<br />\n";
}

return $return_cats;

}

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!
Quote Reply
Re: [Andy] Need Help - Main Categories Global In reply to
Hmm it still says it wont compile

Code:
sub {
my $table = $DB->table('Category');
my $return_cats;

$table->select_options ('ORDER BY Name ASC');
my $sth = $table->select( { FatherID => '0' } );

while (my $hit = $sth->fetchrow_hashref) {
$return_cats .= "<a href=\"/" . $table->as_url($hit->(Full_Name)) . "/\">" . $hit->{Name} . "</a><br />\n";
}

return $return_cats;
}


I tried adding the $table->as_url($hit->(Full_Name))
Quote Reply
Re: [kzap] Need Help - Main Categories Global In reply to
Sorry, missed this one.

$hit->(Full_Name)

...should be;

$hit->{Full_Name}

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!
Quote Reply
Re: [kzap] Need Help - Main Categories Global In reply to
$hit->(Full_Name)

should be

$hit->{Full_Name}

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Need Help - Main Categories Global In reply to
1 minute between posts, but almost ideantical Tongue

Chees

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!
Quote Reply
Re: [Andy] Need Help - Main Categories Global In reply to
thank you very much to both you of. Problem fixed. :)