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
Similar Topics
-
Toggle Show Hide-0Javascript
PHP - MySQL
First post
Hello CoursesWeb,
I have sql document with 4 results from-out database.
But I can`t open the results from the post_id ????
What do I do wrong...
Last post
Try the following code. See the differences.
<?php
echo '<div id= idd11'. $row .' style= display:none; >';
echo $row ;
echo...