views:

56

answers:

2

Hello, i tryed to follow that great tutorial (STAR rating with css : http://stackoverflow.com/questions/1987524/turn-a-number-into-star-rating-display-using-jquery-and-css)

but i've just a big problem : When i do

<span class="stars">1.75</span>

or

$foo='1.75';
echo '<span class="stars">'.$foo.'</span>

the stars is correctly shown, but as soon as i do :

while($val = mysql_fetch_array($result)) 
{  
$average =  ($val['services'] + $val['serviceCli']  + $val['interface'] + $val['qualite'] + $val['rapport'] )  / 5 ;

<span class="stars">.$average.</span>
}

the stars stops working

i double checked the data type in mysql : they're all TINYINT(2)

and i tryed that :

$average = intval($average);

but it's still not working,

Thank you

A: 

no, var_dump($val) gives me ALL the value i get from my big request (text, varchar, int) [example :

array(38) { [0]=>  string(28) "http://www.crystal-serv.com/" 
["siteweb"]=>  string(28) "http://www.crystal-serv.com/" 
[1]=>  string(1) "0" ["offreDedie"]=>  string(100) 
"tick rouge" [2]=>  string(1) "0" ["coupon"]=> 

..........

Tristan
Do you actually need to be retrieving all of the data here?
SeanJA
+1  A: 

I think your problem may be that the value you have is greater than the 5 allowed in that example.

What you want to do is weight the items such that the total for $average is less than or equal to 5.

$average = (
    ( $val['services'] / $maxServices )
    + ( $val['serviceCli'] / $maxServiceCli )
    + ( $val['interface'] / $maxInterface )
    + ( $val['qualite'] / $maxQualite )
    + ( $val['rapport'] / $maxRapport )
);

The weighting could be even, so each of the values will be less than or equal to 1, or they could have different weights so services is worth more than qualite (and so on).

SeanJA
oh my god. i never thought i would be that stupid.in fact, max stars = 5 , my averages are on 10, so i always have <5 values. *need some sleep*thanks, sorry to have bother you with THAT kind of stupid problem.
Tristan
Well, I thought of that too.. BUT the JavaScript catches this situation and sets all values > 5 to exactly 5. So this shouldn't be the solution to the problem..
halfdan
I have a feeling that @halfdan correct, this doesn't solve the problem since your problem was that you were not getting any data back at all...?
SeanJA
no, in fact, it was entirely my fault, all data that i requested are on 10 (i mean, 8/10 + 9/10 +6 /10 ... DIVIDE BY 5 gave me all the values.The stars were all set to 5, that's why i told 'the stars stops working' (i should have precised that they were all set to 5 my bad)
Tristan
You should be able to change the css, javascript and double widen the image to make it go to 10 if you want though.
SeanJA