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

Global to show certain cats

Quote Reply
Global to show certain cats
Hi all, have a problem with this global. It should select all cats with FatherID = 0 and field Menu = 'Links'
sorted by another field named 'Sorter':
It seems it is sorted by ID instead:

Code:
sub {
my $tags = shift;
my $cat_db = $DB->table ('Category');
my $sth = $cat_db->select (['Full_Name','Number_of_Links','Has_New_Links'], { FatherID => 0, Menu => 'Links' });
$cat_db->select_options ('ORDER BY Full_Name ASC');
my $output;
while (my ($name,$links,$new) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($name);
if ($new eq 'Yes')
{$new = "<span class=new>NEU</span>"}
else {$new = ""}
$output .= qq~<a href="/$url">$name</a> ($links) $new<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;
}

Last edited by:

Robert: Feb 28, 2002, 1:55 PM
Quote Reply
Re: [Robert] Global to show certain cats In reply to
Isn't it sorting by Full_Name ?
Quote Reply
Re: [RedRum] Global to show certain cats In reply to
No, really not. I sit here now for an hour, but i still stuck.
It┤s sorted by ID .
It seems that the options aren┤t used here.
If i left them i got the same result.
Robert

PS: There is an error above, while it must be named:

Code:
sub {
my $tags = shift;
my $cat_db = $DB->table ('Category');
my $sth = $cat_db->select ({FatherID => 0, Menu => "Links"},['Full_Name','Number_of_Links','Has_New_Links']);
$cat_db->select_options('ORDER BY Sorter ASC', 'LIMIT 50');
my $output;
while (my ($name,$links,$new) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($name);
if ($new eq 'Yes')
{$new = "<span class=new>NEU</span>"}
else {$new = ""}
$output .= qq~<a href="/$url">$name</a> ($links) $new<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;
}

Last edited by:

Robert: Feb 28, 2002, 3:12 PM
Quote Reply
Re: [Robert] Global to show certain cats In reply to
Code:
my $sth = $cat_db->select ({FatherID => 0, Menu => "Links"},['Full_Name','Number_of_Links','Has_New_Links']);
$cat_db->select_options('ORDER BY Sorter ASC', 'LIMIT 50');


Don't you have to order by one of the selected fields??


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [Robert] Global to show certain cats In reply to
Hi,

You must set the select_options before you call select. =) Once you call select, the SQL is generated and the query is run, too late to change the sort order.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Global to show certain cats In reply to
So obvious :)


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.