Show total results from rating in mysql
Discuss coding issues, and scripts related to PHP and MySQL.
-
JanMolendijk
- Posts:282
- Location:Holland Rotterdam
Show total results from rating in mysql
I have a rating script where new people able to rate from 1 till 5.
Now i have this simple code what shows the total number of rates:
Code: Select all
<?php
include('../connection.php');
$article_id = (int) $_GET['article_id'];
$result = $conn->query("SELECT COUNT(*) FROM `article_rating` WHERE article_id='" . $article_id . "'");
$row = $result->fetch_row();
echo 'My Score ', $row[0];
?>
I wanna have the total score which the people rated on the article_id.
this is my data-base
I hope you can help me out
Admin
Posts:805
Hello
If you want to get the value of the total ratings in the "rating" column, you can use the mysql SUM() instruction.
Code: Select all
$sql ="SELECT SUM(rating) AS t_rate FROM article_rating WHERE article_id=". $article_id;
JanMolendijk
Posts:282
Thank you so mutch Admin great work