Bir kullanıcı bir oy atmalarını komut benim veritabanını günceller ama alışkanlık onun oy hariç olmuştur kullanıcıya anlatmak için aşağıdaki aşağıdaki kodu görüntüler.
//This will output the movie id, new rating, new votes, and a message.
echo "<result id='".$id."' rating='".$rating."' votes='".$votes."'>Vote cast and saved.</result>n";
Nasıl bir kullanıcı she girer ya da oy olduğunda görüntülemek için yukarıdaki kodu almak için bu sorunu çözebilirsiniz?
Ben sorun olduğunu düşünüyorsanız burada aşağıda kod parçasıdır.
if(mysql_num_rows(mysql_query("SELECT * FROM `voters` WHERE `id`='".$id."' && `ip`='".$ip."'")) == 0) {
//This will insert the information about the user, so they can't vote for the same movie again.
mysql_query("INSERT INTO `voters`(`id`, `ip`) VALUES('".$id."', '".$ip."')");
//This will add one more vote and add the rating to the total rating.
mysql_query("UPDATE `movies` SET `votes`=votes+1, `rating`=rating+".$vote_cast." WHERE `id`='".$id."'") or die(mysql_error());
//This will retrieve the newly updated data about the movie.
$data = mysql_fetch_array(mysql_query("SELECT * FROM `movies` WHERE `id`='".$id."'"));
//This will get the average rating and round it to one decimal place.
$rating = round($data['rating']/$data['votes'], 1);
$votes = $data['votes'];
//This will change the output type to XML, instead of HTML.
header('Content-Type: text/xml');
header('Pragma: no-cache');
//Required header in valid XML files
echo '<?xml version="1.0" encoding="UTF-8"?>'."n";
//This will output the movie id, new rating, new votes, and a message.
echo "<result id='".$id."' rating='".$rating."' votes='".$votes."'>Vote cast and saved.</result>n";
}else{
////This will change the output type to XML, instead of HTML.
header('Content-Type: text/xml');
header('Pragma: no-cache');
////Required header in valid XML files
echo '<?xml version="1.0" encoding="UTF-8"?>'."n";
//This message will be shown if they have already voted,
echo "<result id='".$id."' rating='-1' votes='-1'>You have already voted.</result>n";
}
}
Tamam belki o bunun altında benim Ajax bu kod parçası bana sorun veriyor bulunuyor.
function statechange_rate() {
if (http.readyState == 4) {
var xmlObj = http.responseXML;
var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data;
var id = xmlObj.getElementsByTagName('result').item(0).getAttribute("id");
var votes = xmlObj.getElementsByTagName('result').item(0).getAttribute("votes");
var rating = xmlObj.getElementsByTagName('result').item(0).getAttribute("rating");
//Before, you may have noticed we set votes="-1" if they had already voted, this was just to provide an easy way to check the return of our script.
if(votes != -1) {
//This will inform the user about the vote they have cast.
document.getElementsByName('output_' + id).item(0).innerHTML = "<br />" + html;
//This will set a delay to make that message go away in 5000 miliseconds (5 seconds).
window.setTimeout("document.getElementsByName('output_" + id + "').item(0).innerHTML = '';", 5000);
//This will update the rating on the page to the new one.
document.getElementsByName('rating_' + id).item(0).innerHTML = rating;
document.getElementsByName('votes_' + id).item(0).innerHTML = votes;
}else{
document.getElementsByName('output_' + id).item(0).innerHTML = "<br />" + html;
window.setTimeout("document.getElementsByName('output_" + id + "').item(0).innerHTML = '';", 5000);
}
}
}