像系统不能正常工作

时间:2016-01-13 05:57:40

标签: javascript php html ajax

我已经使用ajax在我的页面上加载评级系统,但它显示我的评分只有1个帖子而不是其他帖子

enter image description here

enter image description here

正如您从上面的图片中看到的那样,它显示的是1个帖子的评级而不是另一个帖子的评级,我确信我的数据库已填写两个帖子

我的ajax

<script>
//where $mypostid is already set in my file
function load'.$mypostid.'()
{
    if(window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("echoresult'.$mypostid.'").innerHTML=xmlhttp.responseText;
        }
    }
    parameters="id='.$mypostid.'";
    xmlhttp.open("POST","like.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send(parameters);
}
window.addEventListener("load",load'.$mypostid.');
</script>

my like.php

<?php
$connection30=mysqli_connect('localhost','root','123456789','register');
if(isset($_POST['id']))
{$postid=$_POST['id'];
$queryselect=mysqli_query($connection30,"select * from likes where postid='$postid'");
while($rowselect=mysqli_fetch_array($queryselect))
{
    $countlikes=$rowselect['likes'];
    $countdislikes=$rowselect['dislikes'];
    $likepercentage=($countlikes/($countlikes+$countdislikes))*100;
    echo ceil($likepercentage).'% people liked this';
}}
?>

和我的div元素用于显示评级

<div id="echoresult'.$mypostid.'"></div>

0 个答案:

没有答案