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

last post global : well coded ?

Quote Reply
last post global : well coded ?
I, could you tell me if the following global is well coded... I use it to display some posts on my homepage but I have often an error message :

GT::SQL::Table (32144): Wrong argument passed to this subroutine. Usage: Could not create a condition object out of arguments.
at /home/web/cgi-bin/gforum/admin/GT/SQL/Table.pm line 643


Here is the global

sub {
my $tags = shift;
my $post_db = $DB->table ('Post');
$post_db->select_options ('WHERE post_root_id=0', ' AND forum_id_fk NOT IN (7,8)',
'ORDER BY post_time DESC', 'LIMIT 10');
my $sth = $post_db->select;
my @output;
while (my $post = $sth->fetchrow_hashref)
{
push @output, $post;
}

return { post_loop => \@output };
}



Txs
Regards
FMP
Quote Reply
Re: [fmp] last post global : well coded ? In reply to
select_options isn't meant to be used like that - generally, it's meant for ORDER BYs, LIMITs, but not for the WHERE clause - try instead:

$post_db->select_options ('ORDER BY post_time DESC', 'LIMIT 10');
my $sth = $post_db->select(GT::SQL::Condition->new(post_root_id => '=' => 0, forum_id_fk => '!=' => [7,8]));

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] last post global : well coded ? In reply to
In Reply To:
select_options isn't meant to be used like that - generally, it's meant for ORDER BYs, LIMITs, but not for the WHERE clause - try instead:

$post_db->select_options ('ORDER BY post_time DESC', 'LIMIT 10');
my $sth = $post_db->select(GT::SQL::Condition->new(post_root_id => '=' => 0, forum_id_fk => '!=' => [7,8]));


Hi

txs for your answer

My global is now

sub {
my $tags = shift;
my $post_db = $DB->table ('Post');
$post_db->select_options ('ORDER BY post_time DESC', 'LIMIT 10');
my $sth = $post_db->select(GT::SQL::Condition->new(post_root_id => '=' => 0, forum_id_fk => '!=' => [7,8]));
my @output;
while (my $post = $sth->fetchrow_hashref)
{
push @output, $post;
}

return { post_loop => \@output };
}

It works except that this global displays some threads of all my forums... I don't understand because it shoudn't display the threads from my Forum '7' and my forum '8'...

any idea....

txs
FMP
Quote Reply
Re: [Jagerman] last post global : well coded ? In reply to
Hi

it is still displaying some threads from my forum_id_fk=7 and from forum_id_fk=8... it shoundn't because of the following : "forum_id_fk => '!=' => [7,8]"

Any idea why the condition isn't working ?

Regards
FMP
Quote Reply
Re: [Jagerman] last post global : well coded ? In reply to
hi everybody

any help ? Unsure

Regards
FMP