ajax php星级系统(仅显示mysql数据库中的平均日期)

ajax php星级系统(仅显示mysql数据库中的平均日期),php,javascript,ajax,Php,Javascript,Ajax,我需要一个评级系统,显示在php的平均评级。我完成了评级过程(保存和更新过程)。我只需要用php显示平均评级(使用PHPAJAX评级系统) 当我从数据库中检索数据时,出现了错误。代码如下: <?php $con = mysql_connect("localhost","root",""); if(!$con){ echo "Connection to the Database Consol

我需要一个评级系统,显示在php的平均评级。我完成了评级过程(保存和更新过程)。我只需要用php显示平均评级(使用PHPAJAX评级系统)

当我从数据库中检索数据时,出现了错误。代码如下:

<?php
    $con = mysql_connect("localhost","root","");
    if(!$con){
        echo "Connection to the Database Console was Unsuccessful";
    }
    $select = mysql_select_db("oilandgas13",$con);
    if(!$select){
        echo "Connection to the Database was Unsuccessful";
    }

$add_coun= "SELECT sum(rating) sum, count(id) count from comments WHERE item_id = $itemID AND status=1";
        
        $result = mysql_query($add_coun,$con);
        if(!$result)
        {
        echo "query was not successfully";  
        }
        
        $result = mysql_fetch_object($result);
        
        $sum = $result->sum;
        $count = $result->count;
        $rating = $sum / $count;
        
        echo $rating;
?>

我犯了这样的错误:

警告:mysql\u fetch\u object():在第19行的C:\wamp\www\final work\u apr51\final work\u apr51\calculation.php中,提供的参数不是有效的mysql结果资源

警告:第23行C:\wamp\www\final work\u apr51\final work\u apr51\calculation.php中被零除


也许这能帮到你

    $link = mysqli_connect("localhost","mysqlusername","mysqlpassword","dbname");
    $rating = mysql_real_escape_string($_GET['id']);
    $q = mysqli_query($link,"SELECT * FROM ratings WHERE id='{$rating}'"); //Get our ratings by the page that has rated

    //Die if id dont exist!
    if(mysqli_num_rows($q) == 0) die("Wrong page id!");


    //Select good & bad ratings
    $good = mysqli_query($link,"SELECT * FROM ratings WHERE id='{$rating}' AND value ='yes'");
    $bad = mysqli_query($link,"SELECT * FROM ratings WHERE id='{$rating}' AND value ='no'");

    //Count good & bad ratings
    $gcnt = mysqli_num_rows($good);
    $bcnt = mysqli_num_rows($bad);

    //Calculate
    $totalVotes = $gcnt + $bcnt;

    if($totalVotes == 0){
      echo $totalVotes." votes";
    }
    if($totalVotes > 0){
      echo "<font color='green'>".$totalVotes." votes</font>";
    }
    if($totalVotes < 0){
      echo "<font color='red'>".$totalVotes." votes</font>";
    }        
$link=mysqli_connect(“localhost”、“mysqlusername”、“mysqlpassword”、“dbname”);
$rating=mysql\u real\u escape\u字符串($\u GET['id']);
$q=mysqli_查询($link,“SELECT*FROM ratings,其中id='{$rating}')//通过已评级的页面获取我们的评级
//如果我不存在就死吧!
如果(mysqli_num_rows($q)==0)死亡(“错误的页面id!”);
//选择好的和坏的评级
$good=mysqli_查询($link,“SELECT*FROM ratings,其中id='{$rating}'和value='yes');
$bad=mysqli_查询($link,“SELECT*FROM ratings,其中id='{$rating}'和value='no');
//计算好的和坏的评分
$gcnt=mysqli\u num\u行($good);
$bcnt=mysqli\u num\u行($bad);
//算计
$TotalVoces=$gcnt+$bcnt;
如果($TotalVoces==0){
echo$TotalVoces.“投票”;
}
如果($TotalVoces>0){
回声“$TotalVoces.”选票;
}
如果($totalvoces<0){
回声“$TotalVoces.”选票;
}        

但你的问题是什么?你有什么问题?你尝试过哪些方法不起作用?你应该考虑使用MySQL或PDO而不是贬低的MySQL函数。您还应该添加错误处理来记录您收到的错误。谢谢您没有删除它。投票是真正的MVP。我会把我的留给你的,@OrelBiton