如何从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

$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