MySQL和PHP-不是唯一的表/别名 [英] MySQL & PHP - Not unique table/alias

查看:166
本文介绍了MySQL和PHP-不是唯一的表/别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到下面列出的以下错误,想知道如何解决此问题.

I get the following error listed below and was wondering how do I fix this problem.

Not unique table/alias: 'grades'

这是我认为给我带来问题的代码.

Here is the code I think is giving me the problem.

function getRating(){
$dbc = mysqli_connect ("localhost", "root", "", "sitename");

$page = '3';

$sql1 = "SELECT COUNT(*) 
         FROM articles_grades 
         WHERE users_articles_id = '$page'";

$result = mysqli_query($dbc,$sql1);

if (!mysqli_query($dbc, $sql1)) {
        print mysqli_error($dbc);
        return;
}

$total_ratings = mysqli_fetch_array($result);

$sql2 = "SELECT COUNT(*) 
         FROM grades 
         JOIN grades ON grades.id = articles_grades.grade_id
         WHERE articles_grades.users_articles_id = '$page'";

$result = mysqli_query($dbc,$sql2);

if (!mysqli_query($dbc, $sql2)) {
        print mysqli_error($dbc);
        return;
}

$total_rating_points = mysqli_fetch_array($result);
if(!empty($total_rating_points) && !empty($total_ratings)){
// set the width of star for the star rating
$rating = (round($total_rating_points / $total_ratings,1)) * 10; 
echo $rating;
} else {
    $rating = 100; 
    echo $rating;
}
}

推荐答案

问题似乎在这里:

SELECT COUNT(*) 
FROM grades 
JOIN grades ON grades.id = articles_grades.grade_id
WHERE articles_grades.users_articles_id = '$page'"

您正在尝试将表格成绩与其自身联系起来.您可能打算加入Articles_grades.

You are trying to join the table grades to itself. You probably meant to join with articles_grades.

这篇关于MySQL和PHP-不是唯一的表/别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆