Gossamer Forum
Quote Reply
Understanding Subs
I have been looking at a lot of sub that have been mentioned on this forum, but my perl?? is not up to a hugh amount.

Take this one for instance

http://www.gossamer-threads.com/...s/Detailed/1989.html

That produces a good result, but I would like to break it down so for example I could just get the link and title and not the description.

This bit looks like the business aspect:

while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}

Are there any threads on this sort of thing, I have looked with little sucess. Altough it would be nice to find a solution to this it would be more prudent to know how to do it in the first place so that I could build up the output in what ever form i wanted.

Cheers
Quote Reply
Re: [ukseo] Understanding Subs In reply to
If you only want to do basic globals, then I guess taking a look at the current globals if the best way to go. Obvioulsy learning Perl itself makes things easier ... but personally, I've found that you learn a LOT better from working examples, which you can then dicept, and work out how they work.

Something like this should do for what you are asking;

Code:
sub {

my $tags = shift;

my ($cat_id, $cat_name) = each %{$DB->table('Links')->get_categories($tags->{ID})};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options("ORDER BY $CFG->{build_sort_order_category}");

my $sth = $link_db->select( ['Links.Title','Links.URL'],{ CategoryID => $cat_id });

my $output = '';
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}


The bit in bold basically just tells GT::SQL that we only want to grab the lsql_Links.URL and lsql_Links.Title fields (which obviously uses up less memory, as there are less "junk" details, which you are not going to use).

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!
Quote Reply
Re: [Andy] Understanding Subs In reply to
Cheers Andy

Thays what I try to do, bodge existing code to learn. I did try what you suggested but I get an error

Detail Page Title (active link)
Unknown Tag: 'Description'
...Read More (active link)

Is is a big job to explain how the output is generated

$output .= Links::SiteHTML::display('link', $link);

Can I do something the following

$output .= ''
while (my $hit = $sth->fetchrow_hashref) {
$output.= "<a href=\"/" $url "/\">" $name "</a><br />\n";
$i++;
}

Regards

Last edited by:

ukseo: Oct 26, 2004, 7:47 AM
Quote Reply
Re: [ukseo] Understanding Subs In reply to
Ok, I'll try and explain =)

my $sth = $link_db->select( ['Links.Title','Links.URL'],{ CategoryID => $cat_id });

The ['Links.Title','Links.URL'] part, is basically telling the SQL query, that we only want to grab the Title and URL for that link. i.e <%Description%> will not be available, as we didn't specifically ask to bring it in. simply removing this section will bring in all the fields again.

In regards to;

Code:
$output.= "<a href=\"/" $url "/\">" $name "</a><br />\n";

Sure thing. I'd recommend something like this though, to minamize the number of escapes you need to use =)

Code:
$output.= qq|<a href="$url">$name</a><br />\n|;

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!
Quote Reply
Re: [Andy] Understanding Subs In reply to
Cheers andy

Seems simple enough, but I get unable to compile.

got some playing to do :(
Quote Reply
Re: [ukseo] Understanding Subs In reply to
Not sure if this is part of the problem, but it looks like you're missing a ; at the end of;

$output .= ''

i.e;

$output .= '';

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!