+ 2

PHP [mysql ] How to display average of data from database into website

I have a table in database called appinfo where I have a column called star where I have data of rating values from 1-5. I want to show average rating on the Web page using php mysql. sample data of star 2 5 5 4

4th May 2018, 3:18 PM
Divyanshu sah
Divyanshu sah - avatar
2 Respuestas
+ 3
Just pull all the data from the database and calculate the averages like normal. For mean just add up the numbers and divide it by the number count.
4th May 2018, 9:01 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 1
I assume you have the php connection to the database already. query: SELECT AVG(`star`) AS `averageRating` FROM `ratings` your return will be 1 row with 1 field names averageRating.
4th May 2018, 4:15 PM
Adam
Adam - avatar