Gossamer Forum
Quote Reply
Loops and Globals
Hi,

I may miss something obvious, but didn't find a solution yet searching the forum for 'loop' and/or 'global' - so I ask this question here in the forum:

I want to calculate the average rating from the reviews (the stars, not 'helpful or not') to display it as a corresponding image on the Top Rated page (in the links description, in addition to the standard Rating value).

So I made a global but then realized that I have to pull out the right values out of the 'Reviews_Loop'.
Unfortunately I have no idea how to do that... Unsure

Could someone please show me the right way?

Thank you!

Andreas
-------------------------------------------------
http://www.archaeologie-online.de
Quote Reply
Re: [Digger] Loops and Globals In reply to
Hi,

You could make a global for it:

sub {
my $tags = shift;
my $id = $tags->{ID} or return "No ID found.";
my $avg = $DB->table('Reviews')->select('AVG(Review_Rating)', { ID => $id })->fetchrow;
return $avg;
}

should do the trick.

Cheers,

Alex
--
Gossamer Threads Inc.

Last edited by:

Alex: Feb 14, 2002, 12:31 AM
Quote Reply
Re: [Alex] Loops and Globals In reply to
Smile

Thank you, Alex.

As usual your solution is much less complicated than the way I tried... Laugh

There is just one little error in your code example:
ID => $id should be Review_LinkID => $id to make it work. Also I return int($avg) to get an integer value that I can use for the star images.

So here is the complete one:

Code:
sub {
my $tags = shift;
my $id = $tags->{ID} or return "No ID found.";
my $avg = $DB->table('Reviews')->select('AVG(Review_Rating)', { Review_LinkID => $id })->fetchrow;
return int($avg);
}

So, thanks again - but wait...
Now I have a solution for my specific problem, but I still don't know how I would get values out of a loop in the globals...

Must be something with while{...}, I think. But what goes in between the brackets?

Crazy

Andreas
-------------------------------------------------
http://www.archaeologie-online.de