Gossamer Forum
Home : Products : Gossamer Links : Discussions :

New Template Global Help

Quote Reply
New Template Global Help
Hello all,
I need to create a new template global function and I needed some help with the sql functions. Basically, I need to write a function that will find the number of new reviews in the last 7 days. Simple enough right? I looked at some perl tutorials and i figured out how to find the date 7 days ago. So that part was easy. THe part im having trouble with is actually querying the db and getting the info back. I'm getting an error and I have no idea why. I basically tried copying the other functions but it still doesnt work. Below is a snippet of the code I am using, where $date is the date 7 days ago.

my $reviews_db = $DB->table('Reviews');
my $count = $reviews_db->select ( { Review_Date => ">$date" }, [ 'COUNT(*)' ] );
return $count;

So, I am trying to execute the query "SELECT count(*) FROM Reviews WHERE Review_Date > '$date'" but I am getting the error "GT::SQL::Driver::MYSQL::sth=HASH(0x84acee0)". I'm a total noob to linksql and perl and I'm betting this is a pretty easy problem to solve so I would really appreciate the help. I've been stuck on this for almost a month now. Thanks in advance!
Quote Reply
Re: [kennyl] New Template Global Help In reply to
Hi,

Unfortunately you can't put that condition in a select statement. If you need to specify that a value is larger than, smaller than, LIKE, NOT LIKE, etc., you need a condition. Also, for a count, use count rather than select.

Hopefully this should work:

my $reviews_db = $DB->table('Reviews');
my $cond = $GT::SQL::condition->new('Review_Date', '>', $date);
my $count = $reviews_db->count ($cond);
return $count;
Quote Reply
Re: [afinlr] New Template Global Help In reply to
this seems like it SHOULD work, but i get this error:

Links (9211): Links::fatal called at (eval 25) line 11 with arguments
(Can't call method "new" on an undefined value at (eval 25) line 11.).

Frown i looked through Condition.pm and it seems everything is right. I know there's nothing wrong with the variable $date because i replaced it with a constant but still nothing.
any ideas?
Quote Reply
Re: [kennyl] New Template Global Help In reply to
so i changed $GT::SQL::condition to GT::SQL::Condition and it works perfectly now, thanks!

Quote Reply
Re: [kennyl] New Template Global Help In reply to
Oops - sorry about that - well done for working out the problem.