php - 评级系统协助

标签 php jquery mysql ajax

我正在使用 http://net.tutsplus.com/tutorials/html-css-techniques/building-a-5-star-rating-system-with-jquery-ajax-and-php/ 中的评级脚本

但我希望它将评分上传到数据库并阻止一个人一直对同一张照片投票。

这是我上传和设置 cookie 的脚本:

<?php 
// Get id and voted value
$id = $_POST['widget_id'];
preg_match('/star_([1-5]{1})/', $_POST['clicked_on'], $match);
$vote = $match[1];

// Connect to database and find the row which have the id
$get = mysql_query("SELECT * FROM ratings WHERE id = '$id'");

while ($getdata = mysql_fetch_array($get)) {
    $total_votes = $getdata['total_votes'];
    $total_value = $getdata['total_value'];

    // See if the votes and value is 0 and if it aint it update the database and if it is were creating a new row
    if ($total_votes != 0 && $total_value != 0) {
            $total_votes++;
            mysql_query("UPDATE ratings SET total_votes = '$total_votes' WHERE 
                         id = '$id'");
} else {
    mysql_query("INSERT INTO ratings (id, total_votes, total_value) 
                 VALUES ('$id', '1', '$vote')");
}

// Sets the cookie
$value = $id;
// Send a cookie that expires in 24 hours
setcookie($id, $value, time() + 3600 * 24); 
?>

但是如果用户已经投票了,他仍然可以投票,所以我需要某种方式来检查他是否有 cookie 以及从 mysql 表中获取数据并将其发送给用户的方法。

最佳答案

语法错误...

$total_votes = $total_votes . +1;

这会将 1 添加到 $total_votes

$total_votes++;

关于php - 评级系统协助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14148748/

相关文章:

javascript - 如何禁用 html 按钮 jquery

php - 根据已完成的搜索来搜索mysql数据库

javascript - 选择 2 ajax : preselected data in edit mode

javascript - 定位和编辑新创建的行?

javascript - 将表单数据 POST 中的数组发送到 PHP 端点

javascript - Materialise 下拉菜单在移动设备中禁用 Sly jQuery 滚动条

php - Laravel 5 原始选择查询不返回任何内容

php - mySQL 最后排序下划线

mysql - 从多维数组获取值 | JSON

php - 如何定义用于查找数据库表的 ActiveRecord,以便它与枚举常量一样有用?