Gossamer Forum
Quote Reply
Wrong select options
I still had a problem with the select options; in the following global, they are not used !?

Code:
sub {
my $tags = shift;
my $cat_db = $DB->table ('Category', 'Links');
my $sth = $cat_db->select ({FatherID => 8},['Name','Title','Links.Description','Mod_Date']);
$cat_db->select_options('ORDER BY Mod_Date Desc', 'LIMIT 5');
my $output;
while (my ($catname,$title,$desc,$moddate) = $sth->fetchrow_array) {
$output .= qq~$moddate: $title in Rubrik: <a href="/Software/$catname">$catname</a><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#9595FF"><img src="/img/b.gif" width="1" height="1"></td>
</tr>
</table>
~;
}
return $output;
}


BTW: I have another problem with this global; it passes every link a douzend times ?!
The sql i tried ti use is:

Code:
select Links.Title, Links.Description, Links.Mod_Date from Category, Links
where Category.FatherID = '8'
ORDER BY Mod_Date Desc LIMIT 5


Hope someone has an idea?
Robert
Quote Reply
Re: [Robert] Wrong select options In reply to
Hi,

I answered the select_options in your other post.

The SQL you have here is wrong. You want:

SELECT Links.Title, Links.Description, Links.Mod_Date
FROM Category, CatLinks, Links
WHERE Category.FatherID = 8
AND Category.ID = CatLinks.CategoryID
AND Links.ID = CatLinks.LinkID
ORDER BY Mod_Date Desc LIMIT 5

Or using GT::SQL that would be:

my $rel_table = $DB->table('Links', 'CatLinks', 'Category');
$rel_table->select_options ("ORDER BY Mod_Date DESC", "LIMIT 5");
my $sth = $rel_table->select ( ['Title', 'Description', 'Mod_Date'], { FatherID => 8 } );

Hope that helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Wrong select options In reply to
This shows me the way. Great. Thank you.

Code:
sub {
my $tags = shift;
my $cat_db = $DB->table ('Links', 'CatLinks', 'Category');
$cat_db->select_options ("ORDER BY Mod_Date DESC", "LIMIT 5");
my $sth = $cat_db->select ( ['Category.Name', 'Title', 'Links.Description', 'Mod_Date'], { FatherID => 8 } );
my $output;
while (my ($catname,$title,$desc,$moddate) = $sth->fetchrow_array) {
$output .= qq~$moddate: $title in Rubrik: <a href="/Software/$catname">$catname</a><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#9595FF"><img src="/img/b.gif" width="1" height="1"></td>
</tr>
</table>
~;
}
return $output;
}