Głosy są zaliczane ale coś jest skopane z odbieraniem ich.
Fragment odpowiedzialny za przyciski like and dislike
skrypt
$(document).ready(function() { $.each( $('.voting_wrapper'), function(){ var unique_id = $(this).attr("id"); postdata = {'opinia':'glosuj','unique_id':unique_id, 'vote':'fetch'}; $.post('includes/ajax-reviews-votes.php', postdata, function(response) { $('#'+unique_id+' .up_votes').text(response.vote_up); $('#'+unique_id+' .down_votes').text(response.vote_down); },'json'); }); $(".voting_wrapper .voting_btn").click(function (e) { var clicked_button = $(this).children().attr('class'); var unique_id = $(this).parent().attr("id"); if(clicked_button==='down_button') { postdata = {'opinia':'glosuj','unique_id':unique_id, 'vote':'down'}; $.post('includes/ajax-reviews-votes.php', postdata, function(data) { $('#'+unique_id+' .down_votes').text(data); }).fail(function(err) { }); } else if(clicked_button==='up_button') //user liked the content { postdata = {'opinia':'glosuj', 'unique_id':unique_id, 'vote':'up'}; $.post('includes/ajax-reviews-votes.php', postdata, function(data) { $('#'+unique_id+' .up_votes').text(data); // alert("Thanks! For Liking This Content."); }).fail(function(err) { //alert(err.statusText); }); } }); });
Plik ajax-reviews-votes.php
switch ($user_vote_type) { case 'up': $result = mysqli_query($sql_con,"SELECT glos_plus FROM reviews WHERE id='$unique_content_id' LIMIT 1"); $get_total_rows = mysqli_fetch_assoc($result); if($get_total_rows) { mysqli_query($sql_con,"UPDATE reviews SET glos_plus = glos_plus+1 WHERE id='$unique_content_id'"); } break; ##### User disliked the content ######### case 'down': $result = mysqli_query($sql_con,"SELECT glos_minus FROM reviews WHERE id='$unique_content_id' LIMIT 1"); $get_total_rows = mysqli_fetch_assoc($result); if($get_total_rows) { mysqli_query($sql_con,"UPDATE reviews SET glos_minus=glos_minus+1 WHERE id='$unique_content_id'"); } if($get_total_rows) { } break; case 'fetch': $result = mysqli_query($sql_con,"SELECT glos_plus,glos_minus FROM reviews WHERE id ='$unique_content_id' LIMIT 1"); $row = mysqli_fetch_assoc($result); $vote_up = ($row["glos_plus"])?$row["glos_plus"]:0; $vote_down = ($row["glos_minus"])?$row["glos_minus"]:0; break; }