Php mysql用户评级系统问题与评级不同的餐馆

我在用户评级系统中遇到问题。 一旦我评价一家餐馆并去另一家餐馆,我不能评价该餐厅,它会被禁用。

我注意到这在index.php中有一个 echo starBar(5, 103, 16); 中间的一个103mediaId当我改变这个id没有并且去投票然后它工作并且一旦我再次使用这个媒体id评价没有人可以在任何地方评价时有这个问题。

完整代码如下:

的index.php

 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 = '
'; $starBar .= '
'; for ($i=1; $i<=$numStar; $i++) { $starBar .= '<div class="'; if ($i
'; } $starBar .= '
'; $starBar .= '
'; // 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 .= '
'; $starBar .= '
'; // Return the text "Thank you for rating" when someone rate $starBar .= '
'; return $starBar; } echo starBar(5, 103, 16); // We create star bar ?>

政党成员星级rating.js

 function rateMedia(mediaId, rate, numStar) { $('.box' + mediaId).html(''); // 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('
Thank you for rating
'); // Return "Thank you for rating" // We update the rating score and number of rates $('.resultMedia' + mediaId).html('
Rating: ' + data.avg + '/' + numStar + ' (' + data.nbrRate + ' votes)
'); // 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
'; } $('#' + 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 += '
'; } $(this).css('position', 'relative').append('
' + newStarBar + '
'); // 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(); }); });

Interesting Posts