dongyinju5977 2010-04-24 02:09
浏览 35
已采纳

PHP没有给我一个数字类型

I tried to follow the instructions in this question: STAR rating with 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 tried this:

$average = intval($average);

but it's still not working,

  • 写回答

2条回答 默认 最新

  • duandi4815 2010-04-24 02:32
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法