You are here:  » Show ratings image for a particular numerical rating

Support Forum



Show ratings image for a particular numerical rating

Submitted by paddyman on Wed, 2010-02-24 23:45 in

Hi David,

Sorry about the title, change if required !!

I have access to a feed with numerical average ratings specified in a ratings field. Have imported this field and currently showing ratings as numerical values, such as 3.75.

<?php
 
if( $mainProduct["averagerating"]): 
?>

<?php
 
print  $mainProduct["averagerating"]; 
?>

<?php
 
endif; 
?>

Just wondering how I would display your rating star images instead of the numerical value (i.e. replace 3.75 with your 3star image 3.gif) as follows

ratings between 0-1 = 1.gif
ratings between 1-2 = 2.gif
ratings between 2-3 = 3.gif
ratings between 3-4 = 4.gif
ratings between 4-5 = 5.gif

Any ideas ?

Hope this makes sense :)

Cheers

Adrian

Submitted by support on Thu, 2010-02-25 10:45

Hi Adrian,

Use the value of ceil($mainProduct["averagerating"]) which will round up; so 3.75 will return 4 which you can then pass to the tapestry_stars() function which returns the image HTML; for example:

<?php
  
print tapestry_stars(ceil($mainProduct["averagerating"]));
?>

Cheers,
David.

Submitted by paddyman on Thu, 2010-02-25 13:56

Hi David,

Thanks for this.

Getting an error before the stars are displayed.

Warning: Missing argument 2 for tapestry_stars(), called in /home/......./html/product.php on line 37 and defined in /home/....../includes/tapestry.php on line 61

Any ideas ? Can send you on any necessary files if required.

Cheers

Adrian

Submitted by support on Thu, 2010-02-25 14:32

Hi Adrian,

Sorry - it should be:

<?php
  
print tapestry_stars(ceil($mainProduct["averagerating"]),"");
?>

Cheers,
David.

Submitted by paddyman on Thu, 2010-02-25 18:55

Thanks yet again David.