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

Shorter code, less queries

Quote Reply
Shorter code, less queries
Since many years i use something like this (shorted) on Category.html

Code:
sub {
my $tags = shift;
my $catid = $tags->{ID};

my $all_db = $DB->table('Links','CatLinks','Category');
$all_db->select_options ("", "");

my $cond = GT::SQL::Condition->new(
'FatherID','=',$catid,
'Category.ID','=','CatLinks.CategoryID',
'Links.ID','=','CatLinks.LinkID'
);

my $sth = $all_db->select ( ['Links.ID','Contact_Name','URL','Name'], $cond);

while (my ($lid, $cname, $url, $catname) = $sth->fetchrow_array) {

my $links_db = $DB->table('Links');
my $fh = $links_db->file_info( 'picture', $lid );
my $location = $fh->File_RelativePath;
if ($fh->File_Name =~ /\.(jpg|gif)$/) {
$bild="<img src='/img$location'>";
}


$output .= "<a href=\"$url\">$bild</a><br>";

}

return $output;
}

I want all Links from cities in a country; then the picture for the Link.

USA CatID=33
Cities With FatherID = 33

For every Link i take again infos from the table Links; maybe it is better to make a LEFT JOIN or something else?