Aparece el siguiente error y me pregunto cómo puedo solucionar este problema.MySQL y PHP: tabla no única/alias
Not unique table/alias: 'grades'
Aquí está el código que creo me está dando el problema.
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;
}
}
La condición ON sugeriría que es un error tipográfico – VolkerK
Parece ser una respuesta muy antigua, pero me quedé atrapado en la consulta Creo que 'JOIN grades' debería ser' JOIN articles_grades' –