dps123456789 2015-01-30 00:34
浏览 26
已采纳

图像无效的简单评分滑块

I am trying to setup a simple image scoring system on a site, you click on a thumbnail, a modal box with image opens containing a jquery slider, move it to rate the image and it writes the value back to mysql. Problem is I cannot get it to save the value for the correct image, it always writes back the score value to the last entry in the table. Can someone help. Thanks in advance.

<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'");
  • 写回答

1条回答 默认 最新

  • duanniu3385 2015-03-13 02:43
    关注

    I have it working perfectly now. I changed the code around a fair bit.

        <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计