好的人我遇到了麻烦我的星级评分系统实际运行但是我无法在表格中插入由ajax选择的星级评分需要一点帮助我已经这样做了。< / p>
脚本
<script>
// rating script
$(function(){
$("#sent-form-msg").hide();
$('.rate-btn').hover(function(){
$('.rate-btn').removeClass('rate-btn-hover');
var therate = $(this).attr('id');
for (var i = therate; i >= 0; i--) {
$('.rate-btn-'+i).addClass('rate-btn-hover');
};
});
$('.rate-btn').click(function(){
var therate = $(this).attr('id');
var dataRate = 'act=rate&post_id=<?php echo $row->id; ?>&user_id=<?php echo $_SESSION['user_id'] ?>&rate='+therate; //
$('.rate-btn').removeClass('rate-btn-active');
for (var i = therate; i >= 0; i--) {
$('.rate-btn-'+i).addClass('rate-btn-active');
};
$.ajax({
type : "POST",
url : "ajax/processa_avaliacao.php",
data: dataRate,
success: success()
});
function success(){
$("#sent-form-msg").fadeIn();
$("#sent-form-msg").fadeOut(5500).html("<p align='center'>Avaliação Submetida com sucesso! Obrigado pelo seu voto</p>");;
}
return false;
});
});
</script>
星
<div class="rate-ex1-cnt">
<div id="1" class="rate-btn-1 rate-btn"></div>
<div id="2" class="rate-btn-2 rate-btn"></div>
<div id="3" class="rate-btn-3 rate-btn"></div>
<div id="4" class="rate-btn-4 rate-btn"></div>
<div id="5" class="rate-btn-5 rate-btn"></div>
</div>
<div id="sent-form-msg"></div>
Php Code
require_once(&#34; ../ GTM / BD / funcoes.php&#34); ligarBd();
if($_REQUEST['act'] == 'rate'){
//search if the user(ip) has already gave a note
$user = $_POST['user_id'];
$pontos = $_POST['rate'];
$estabelecimento_id = $_POST['post_id'];
$query = mysql_query("SELECT * FROM avaliacoes where user_id= '".$user." ");
while($data = mysql_fetch_assoc($query)){
$rate_db[] = $data;
}
if(@count($rate_db) == 0 ){
mysql_query("INSERT INTO avaliacoes (user_id, estabelecimento_id, pontos)VALUES('".$user.", '".$estabelecimento_id.", '".$pontos.")");
}else{
mysql_query("UPDATE avaliacoes SET pontos= '".$pontos." WHERE user_id = '".$user."");
}
}