dtcmadj31951 2014-11-26 08:49
浏览 348
已采纳

如何从jQuery中的数据库中获取数据?

The values do not pass for "id" and "rate_number" from database."ratingValue" is working, but "id" alert and "num" alert are not working.

Here is my PHP code.

$jsqla = mysql_query("select id,name,rate_score,rate_number,video_image from products where genre='$genre' limit 0,5");

if($jrowa['rate_number'] > 0){ 
  $ratea = $jrowa['rate_score'] / $jrowa['rate_number']; 
}else{ 
  $ratea = 0; 
}

Here is HTML code.

<div class="col-sm-2 portfolio-item" style="width: 20%;">

    <input class="rating form-control input-star-rate" name="rating" value="<?php echo $ratea; ?>" data-min="0" data-max="5" data-step="0.3" data-size="xs" style="display: none; text-align: center;"/>

</div>

Here is jQuery code.

$(function(){
    $(document).ready(function(e) {
        var $stars = $('.input-star-rate');

        $stars.bind('change', function() {
            var $this = $(this); 

            var ratingValue = $this.val();
            alert(ratingValue);

            var id = $this.attr("id");
            alert(id);

            var num = parseInt("$this.attr("rate_number")")+1;
            alert(num);
        });
    });
});
  • 写回答

1条回答 默认 最新

  • drqvsx1228 2014-11-26 08:55
    关注

    You didn't set the id attribute in the <input>.

    $rateid = 0;
    if($jrowa['rate_number'] > 0){ 
      $ratea = $jrowa['rate_score'] / $jrowa['rate_number']; 
      $rateid = $jrowa['id'];
    }else{ 
      $ratea = 0; 
    }
    

    and:

    <input class="rating form-control input-star-rate" id="<?php echo $rateid; ?>" name="rating" value="<?php echo $ratea; ?>" data-min="0" data-max="5" data-step="0.3" data-size="xs" style="display: none; text-align: center;"/>
    

    Same for num (also doesn't work because you need to escape your quotes)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改