图像不起作用的简单评分滑块


Simple scoring slider for images not working

我正在尝试在网站上设置一个简单的图像评分系统,您单击缩略图,打开一个包含jquery滑块的图像模态框,移动它以对图像进行评级,它将值写回mysql。问题是我无法让它保存正确图像的值,它总是将分数值写回表中的最后一个条目。有人可以帮忙吗?提前谢谢。

<div id="<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<p><h3 id="myModalLabel"><?php echo $image_title ?></h3></p>
</div>
<div class="modal-body">
<img src="<?php echo $image_name ?>">
<h4>Photo description:</h4>
<p><?php echo $image_information ?></p>
<h4>Photographer: <?php echo $photographer_name ?></h4>
<h4 for="amount">Score:</h4>
<input type="text" id="amount" readonly style="color:#462a74;  width:16px; font-weight:bold;">
<div id="slider"></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
<script>
$(document).ready(function() {      
$( "#amount" ).val(<?php echo $score; ?>);
$( "#slider" ).slider({
range: "max",
min: 1,
max: 100,
value: <?php echo $score; ?>,
slide: function( event, ui ) {
$( "#amount" ).val( ui.value );
}
});
$("#slider").mouseup(function(){
 var id = '<? echo $id ?>';
  var amount = (document.getElementById('amount').value);
 $.post( "update_score.php", { amount: amount, id:id } );
});
</script>

update_score.php
$id = $_POST['id'];
$score = $_POST['amount'];
$result = $sql->query("UPDATE images SET score = '$score' WHERE id = '$id'");

我现在让它完美运行。我更改了相当多的代码。

    <p><input type="text" id="amount_<? echo $id ?>" class="amount" data slider="true" data-slider-theme="volume" data-slider-range="0,100" data-slider-step="1" value="<?php echo $score ?>"></p>
    <script>
    $("[data-slider]")
    .each(function () {
      var input = $(this);
      $("<span>")
        .addClass("output")
        .insertAfter($(this));
    })
    .bind("slider:ready slider:changed", function (event, data) {
      $(this)
        .nextAll(".output:first")
          .html(data.value.toFixed(3));
    });
    </script>
    <script>
    var id = '<?php echo $id; ?>';
    $(".amount").bind("slider:changed", function (event, data) {
    id = $(this).attr("id");
    $.post( "update_score.php", { amount: data.value, id:id } );
    });
    </script>
    <script>
    var id = '<?php echo $id; ?>';
    $(".comments").bind('keyup paste', function(e) {
        id = $(this).attr("id");
        $.post( "update_comments.php", { comments:e.target.value, id:id }     );
    });
    </script>