how get value from php and use in javascript -
as have define code way rating
<?php foreach($rating $ratingvalue): $total = @round($ratingvalue->tot_rating / $ratingvalue->total_voter ,1); echo $total."/10"; endforeach; ?> as above php code give total ratin , then
starts javascript javascript takes total rating $total 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 function name click directory: baseurl+'./assets/frontend/images/' }); }); </script> when run it 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 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 function name click directory: baseurl+'./assets/frontend/images/' }); }); </script> please me solve can rating
$ratingvalue->tot_rating tot_rating <<< explain please $ratingvalue->total_voter total_voter <<< explain please $total = @round($ratingvalue->tot_rating / $ratingvalue->total_voter ,1); you using ( foreach ) variables classes
Comments
Post a Comment