Javascript Php mysql用户评级系统对不同餐厅的评级存在问题

Javascript Php mysql用户评级系统对不同餐厅的评级存在问题,javascript,php,jquery,Javascript,Php,Jquery,我的用户评级系统有问题。一旦我给一家餐馆打分,然后去了另一家餐馆,我就不能给那家餐馆打分了,它会被禁用 我在index.phpecho starBar(510316)中注意到了这一点中间的一个103是mediaId当我更改此id号并去投票时,出现问题,然后它就工作了,一旦我再次使用此媒体id评分,任何地方都无法评分 完整代码如下: index.php <?php $getRest = $_GET['sid']; function starBar($numStar, $mediaId

我的用户评级系统有问题。一旦我给一家餐馆打分,然后去了另一家餐馆,我就不能给那家餐馆打分了,它会被禁用

我在index.php
echo starBar(510316)中注意到了这一点中间的一个103mediaId当我更改此id号并去投票时,出现问题,然后它就工作了,一旦我再次使用此媒体id评分,任何地方都无法评分

完整代码如下:

index.php

<?php
$getRest    = $_GET['sid'];

function starBar($numStar, $mediaId, $starWidth) { // function with arguments: number of stars, media ID, width of the star image
    global $bdd;
    $cookie_name = 'tcRatingSystem'.$mediaId; // Set up the cookie name
    $sid    = mysql_real_escape_string($_GET['sid']);
    // We get the rate average and number of rate from the database
    $query = $bdd->getOne('SELECT round(avg(rate), 2) AS average, count(rate) AS nbrRate, sr_id AS sr_id FROM rest_rating WHERE media='.$mediaId.' and sr_id = "'.$sid.'"');
    $avgCeil = round($query['average'], 0); // round above or below to show how many selected stars we display

    $getJSON = array('numStar' => $numStar, 'mediaId' => $mediaId); // We create a JSON with the number of stars and the media ID
    $getJSON = json_encode($getJSON);

    // We create the DIV block with selected stars and unselected stars depending of the rate
    $starBar = '<div id="'.$mediaId.'">';
    $starBar .= '<div class="';
    if( !isset($_COOKIE[$cookie_name]) ) $starBar .= 'star_bar';
    $starBar .= '" rel='.$getJSON.' style="width:'.($numStar*$starWidth).'px">';

    for ($i=1; $i<=$numStar; $i++) {
        $starBar .= '<div class="';
        if ($i <= $avgCeil) $starBar .= 'star_selected'; else $starBar .= 'star';
        $starBar .= '"></div>';
    }
    $starBar .= '</div>';
    $starBar .= '<div class="resultMedia'.$mediaId.'" style="font-size: small; color: grey">'; // We show the rate score and number of rates
    if ($query['nbrRate'] == 0) $starBar .= 'Not rated yet';
    else $starBar .= 'Rating: ' . $query['average'] . '/' . $numStar . ' (' . $query['nbrRate'] . ' votes)';
    $starBar .= '</div>';
    $starBar .= '<div class="box'.$mediaId.'"></div>'; // Return the text "Thank you for rating" when someone rate
    $starBar .= '</div>';

    return $starBar;
}

echo starBar(5, 103, 16); // We create star bar     
?>

停止使用不推荐的
mysql.*
API。使用
mysqli.*
PDO
请使用句子标点符号,因为现在我几乎无法从你的问题中挖掘出任何信息。@RajdeepPaul看看这个停止使用不推荐的
mysql.*
API的网站。使用
mysqli.*
PDO
请使用句子标点符号,因为现在我几乎无法从你的问题中找出任何信息。@RajdeepPaul看一下这个
function rateMedia(mediaId, rate, numStar) {
    $('.box' + mediaId).html('<img src="comment/loader-small.gif" alt="" />'); // Display a processing icon
    var data = {mediaId: mediaId, rate: rate}; // Create JSON which will be send via Ajax

    $.ajax({ // JQuery Ajax
        type: 'POST',
        url: 'comment/tuto-star-rating.php', // URL to the PHP file which will insert new value in the database
        data: data, // We send the data string
        dataType: 'json',
        timeout: 3000,
        success: function(data) {
            $('.box' + mediaId).html('<div style="font-size: small; color: green">Thank you for rating</div>'); // Return "Thank you for rating"
            // We update the rating score and number of rates
            $('.resultMedia' + mediaId).html('<div style="font-size: small; color: grey">Rating: ' + data.avg + '/' + numStar + ' (' + data.nbrRate + ' votes)</div>');

            // We recalculate the star bar with new selected stars and unselected stars
            var ratingBar = '';
            for ( var i = 1; i <= numStar; i++ ) {
                ratingBar += '<div class="';
                if (i <= data.avgCeil) ratingBar += 'star_selected'; else ratingBar += 'star';
                ratingBar += '"></div>';
            }

            $('#' + mediaId + ' .star_bar').html(ratingBar).off('mouseenter');
        },
        error: function() {
            $('#box').text('Problem');
        }
    });
}

$(function () {
    $('.star_bar').on('mouseenter', function overBar(event) { // Mouse enter the star bar
        var relData = $.parseJSON($(this).attr('rel')); // Get JSON values: number of stars and media ID

        $(this).css('cursor','pointer');

        // We create a new star bar OVER the previous one with transparent stars
        var newStarBar = '';
        for ( var i = 1; i <= relData.numStar; i++ ) {
            newStarBar += '<div class="no_star" id="' + i + '" title="' + i + '/' + relData.numStar + '" onclick="rateMedia(' + relData.mediaId + ', ' + i + ', ' + relData.numStar + '); return false;"></div>';
        }
        $(this).css('position', 'relative').append('<div id="over' + relData.mediaId + '" style="position:absolute; top:0; left:0;">' + newStarBar + '</div>');

        // When we move the mouse over the new transparent star bar they become blue
        $('#over' + relData.mediaId + ' > div').mouseover(function() {
            var myRate = $(this).attr('id');
            for ( var i = 1; i <= relData.numStar; i++ ) {
                if (i <= myRate) $('#over' + relData.mediaId + ' #' + i).attr('class', 'star_hover');
                else $('#over' + relData.mediaId + ' #' + i).attr('class', 'no_star');
            }
        });
    });

    // Mouse leaves the star bar, we remove the rating bar
    $('.star_bar').on('mouseleave', function overBar(event) {
        var relData = $.parseJSON($(this).attr('rel'));
        $('#over' + relData.mediaId).remove();
    });
});