Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Image Rate Mod

Quote Reply
Image Rate Mod
Hi All,

I've been searching and found the following,

the first mod doesnt seem to work, you can see it here. http://www.adeva.de/rateimg.htm

so i searched here and found this, the problem is, is that it only covers 0-5 my site has 1-10 so how would i incorporate this. http://www.gossamer-threads.com/...ew=&sb=&vc=1


Regards

MDJ1
http://www.isee-multimedia.co.uk
mark@isee-multimedia.co.uk
Quote Reply
Re: Image Rate Mod In reply to
Replace the following codes:

Code:

my $rating = int ($rec->{Rating} / 2);


with the following:

Code:

my $rating = int ($rec->{Rating});


/2 = divide by 2 = 5 images

Deleting /2 will take the whole rating value and associate it to 10 images rather than 5 images...just a little matter of mathematics.

Of course, if you had 20 images, then you would use the following codes:

Code:

my $rating = int ($rec->{Rating} * 2);


Regards,

Eliot Lee
Quote Reply
Re: Image Rate Mod In reply to
Hi eliot,

Im confused do i just add this
Code:
my $rating = int ($rec->{Rating});
my $rec->{rate_img} = "<img src=/images/rate$rating.gif">";
because when i do i get all sorts of errors in the build like
Code:
<H1>Software error:</H1>
<CODE>[Thu Jun 22 04:15:14 2000] HTML_Templates.pm: [Thu Jun 22 04:15:14 2000] H
TML_Templates.pm: Links/HTML_Templates.pm has too many errors.
BEGIN failed--compilation aborted at nph-build.cgi line 33.
</CODE>
<P>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.

[Thu Jun 22 04:15:14 2000] nph-build.cgi: [Thu Jun 22 04:15:14 2000] HTML_Templa
tes.pm: [Thu Jun 22 04:15:14 2000] HTML_Templates.pm: Links/HTML_Templates.pm ha
s too many errors.
[Thu Jun 22 04:15:14 2000] nph-build.cgi: BEGIN failed--compilation aborted at n
ph-build.cgi line 33.
[root@ns admin]# perl nph-build.cgi
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Global symbol "$user" requires explicit package name at Links/HTML_Templates.pm line 86.
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Global symbol "$output" requires explicit package name at Links/HTML_Templates.pm line 86.
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Scalar found where operator expected at Links/HTML_Templates.pm line 99, at end of line
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: (Missing operator before ?)
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Global symbol "$rec" requires explicit package name at Links/HTML_Templates.pm line 99.
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Global symbol "$template" requires explicit package name at Links/HTML_Templates.pm line 99.
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Global symbol "$tags" requires explicit package name at Links/HTML_Templates.pm line 99.
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Global symbol "$dynamic" requires explicit package name at Links/HTML_Templates.pm line 99.
[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Global symbol "$name" requires explicit package name at Links/HTML_Templates.pm line 99.
Content-type: text/html

<H1>Software error:</H1>
<CODE>[Thu Jun 22 04:18:14 2000] HTML_Templates.pm: [Thu Jun 22 04:18:14 2000] HTML_Templates.pm: Links/HTML_Templates.pm has too many errors.
BEGIN failed--compilation aborted at nph-build.cgi line 33.
</CODE>
<P>
Mmm Please enlighten me.



Regards

MDJ1
http://www.isee-multimedia.co.uk
mark@isee-multimedia.co.uk
Quote Reply
Re: Image Rate Mod In reply to
You use the following codes:

Code:

rate_img => &rating_image ($rec->{Rating}),


NOT

Code:

my $rec->{rate_img} = "<img src=/images/rate$rating.gif">";


Then you use <%rate_img%> in your link.html template file.

Regards,


Eliot Lee
Quote Reply
Re: Image Rate Mod In reply to
Hi eliot.

Ive changed it to this, but im still getting an error
Code:
my $rating = int ($rec->{Rating});
rate_img => &rating_image ($rec->{Rating}),
I don'tunderstand from this though were the script will call the image from there is no url?



Regards

MDJ1
http://www.isee-multimedia.co.uk
mark@isee-multimedia.co.uk
Quote Reply
Re: Image Rate Mod In reply to
'=' is used in a perl assignment statement.

'=>' is a HASH assignment, and is used inside a hash-list to assign the value on the right to the key on the left.

the '=>' is functionally equal to a ',' but it makes reading long lists of assignments easier.



http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Image Rate Mod In reply to
Sorry Pugdog,

I see what you are saying, but it doesnt explain the answer to me, the mod i have inserted as eliot said doesnt work.

I need to know if i just need to add this or more?

Sorry to be a simple man, I am trying to get to grips with perl.
SQL seems a bit easier, but perl just baffles me!!



Regards

MDJ1
http://www.isee-multimedia.co.uk
mark@isee-multimedia.co.uk
Quote Reply
Re: Image Rate Mod In reply to
The mod on adeva.de/links.htm works fine for me; maybe i have another code in use at my site.
So i will try to compare the code in use and the code described in my mod this evening and send a message about.

Robert



Quote Reply
Re: Image Rate Mod In reply to
Looking at your errors, you have done something -- either a comma, parenthesis, or something else is out of place probably.

Also,

Code:
my $rating = int ($rec->{Rating});
my $rec->{rate_img} = "<img src=/images/rate$rating.gif">";
You can't define "$rec" with 'my' AFTER you've already used it in the line above, you need to have "$rec" declared before you use it the FIRST time.

$rec should already be defined in the routine. It's the variable that holds the pointer to the current record.

$rec->{'Rating'} should return the value in the field "Rating" of that record.

In the Links table, that is a "REAL" number, so you want to turn it into a integer, by using the int() function on it. This will ALWAYS round DOWN the rating to the next LOWEST rating, not the closest.

my $rating = int ($rec->{Rating});

This defines $rating to be the INTEGER value of the field "Rating"

IT will be returned on scale of 0 to 10.

if you want to use 5 images, you do:

my $rating = int ($rec->{Rating} / 2);

which will divide the "Rating" field in half, then take the integervalue of the result (again, the ROUNDED DOWN .... 9.9 will become '9').

Then, you want to assign that to an image:

$rec->{rate_img} = "<img src=/images/rate$rating.gif">";


That creates a new hash value 'rate_img' and assigns it to be the value on the right side of the equation, which is a URL to an image.

If "rating" was 3, then <img src=/images/rate3.gif">

The tag <%rate_img%> is now available in the template to use to show that image.




http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Image Rate Mod In reply to
Mmm, Still cant get it to work,

but ive managed to get the original working. Thanks for all your help, atleast ive learnt something about perl.



Regards

MDJ1
http://www.isee-multimedia.co.uk
mark@isee-multimedia.co.uk