Raty多重评级

时间:2014-03-25 06:05:26

标签: php jquery raty

我在只读模式下使用Raty星形插件,评级数字来自数据库,我有7个分数,我想要每个人的星级评分。即使我把div放在一个while循环中,我只获得一星评级。请有人帮帮我吗?

$(function() {
    $('#rate').raty({
    path     : '../img',
    readOnly   : true,
     size     : 24,
    starHalf : 'star-half-big.png',
    starOff  : 'star-off-big.png',
    starOn   : 'star-on-big.png',
     score: function() {
    return $(this).attr('data-score');
    }
  });
  });

while($row = $result->fetch_assoc()){ ?>
<div id="rate" data-score="<?php echo $row['rating'];"></div><!--even though I have 7 ratings in the table only one is showing up here -->
 <?php } ?>

1 个答案:

答案 0 :(得分:2)

尝试使用class代替Id,因为Id应该是唯一的

JAVASCRIPT CODE

    $(function() {
        $('.rate').raty({
            path     : '../img',
            readOnly   : true,
             size     : 24,
            starHalf : 'star-half-big.png',
            starOff  : 'star-off-big.png',
            starOn   : 'star-on-big.png',
             score: function() {
            return $(this).attr('data-score');
            }
        });
  });

PHP代码

 while($row = $result->fetch_assoc()){ ?>
    <div class="rate" data-score="<?php echo $row['rating'];"></div><!--even though I have 7 ratings in the table only one is showing up here -->
 <?php } ?>