我已經構建了基於jQuery-php的5星級評分系統。重複點擊時給出錯誤評級的評分系統
將評分插入/存儲在數據庫中,並且沒有命中。
當重複點擊任何星星時,在將數據插入數據庫時存在一些問題,即如果多次連續點擊星星,則不會插入評分,但會插入點擊,然後影響新的結果評分。
這是一個php後端問題,我試圖只在插入評分時插入命中,但它不起作用。
PHP
<?php
$post_rating = '5';
$id = '1';
$database = 'comment-database';
$tablename = 'comment-table';
require_once('rt-connect.php');
$find_data = "SELECT hits, user_rating, rating_total FROM $tablename WHERE id='$id'";
$query = mysqli_query($connection, $find_data) or trigger_error(mysqli_connect_error(), E_USER_ERROR);
$row = mysqli_fetch_assoc($query);
$current_hit = $row['hits'];
$current_rating_total = $row['rating_total'];
$new_hits = $current_hit+1;
$new_rating_total = $current_rating_total + $post_rating;
$new_rating = $new_rating_total/$new_hits;
$new_round_rating = ceil($new_rating/0.5)*0.5;
$update_rating = mysqli_query($connection, "UPDATE $tablename SET user_rating='$new_round_rating' WHERE id='$id'");
if ($update_rating){
$update_hits = mysqli_query($connection, "UPDATE $tablename SET hits='$new_hits' WHERE id='$id'");
$update_rating_total = mysqli_query($connection, "UPDATE $tablename SET rating_total='$new_rating_total' WHERE id='$id'");
}
$find_data2 = "SELECT hits, user_rating, raw_rating, rating_total FROM $tablename WHERE id='$id'";
$query2 = mysqli_query($connection, $find_data2);
$row2 = mysqli_fetch_assoc($query2);
$current_hit2 = $row2['hits'];
$current_rating2 = $row2['user_rating'];
$current_raw_rating_total2 = $row2['raw_rating'];
$current_rating_total2= $row2['rating_total'];
echo $current_hit2.'<br />';
echo $current_rating2.'<br />';
echo $current_raw_rating_total2.'<br />';
echo $current_rating_total2.'<br />';
?>
請參閱並提出任何可能的方式來做到這一點。
謝謝。
你已經標記爲jquery/html/ajax問題,但我沒有看到任何HTML提供。你能提供嗎? – eis