duanjia7912 2013-08-01 06:04
浏览 32

如何从PHP获取价值并在javascript中使用

As i have define the code this way for rating

<?php foreach($rating as $ratingValue):
$total = @round($ratingValue->TOT_RATING / $ratingValue->TOTAL_VOTER ,1);
echo $total."/10";
endforeach;
?>

as from above php code it will give the total ratin and then

starts javascript where javascript takes the total rating as $total where i have defined below

<script language="javascript" type="text/javascript">

var totalRating = <?php echo $total;?>;
var baseUrl = "<?php echo base_url();?>";
$(function() {
$("#rating_simple1").webwidget_rating_sex({
rating_star_length: '5',
rating_initial_value: totalRating,
rating_function_name: '', //this is function name for click
directory: baseUrl+'./assets/frontend/images/'
});
});
</script>

when i run it it will shows error message lik this

<script language="javascript" type="text/javascript">

var totalRating = <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined variable: total</p>
<p>Filename: views/detail.php</p>
<p>Line Number: 69</p>

</div>;
var baseUrl = "http://localhost/aka/";
 $(function() {
 $("#rating_simple1").webwidget_rating_sex({
 rating_star_length: '5',
 rating_initial_value: totalRating,
 rating_function_name: '', //this is function name for click
 directory: baseUrl+'./assets/frontend/images/'
  });
  });
  </script>

please help me to solve it so that i can do my rating

  • 写回答

1条回答 默认 最新

  • dongzhui4927 2013-08-01 06:16
    关注
    $ratingValue->TOT_RATING 
    
    TOT_RATING  <<< explain this please 
    
    $ratingValue->TOTAL_VOTER 
    
    TOTAL_VOTER  <<< explain this please 
    
    $total = @round($ratingValue->TOT_RATING / $ratingValue->TOTAL_VOTER ,1);
    

    you are using the ( foreach ) variables as classes

    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输