This is the table
store_reviews
id rev_star
1 2
2 5
3 4
What I want to do is to get all the rows and add stars and divide by the count of rows (average) like 2+5+4/3
I wrote a code but it doesn't get all the rows added.
<?php
$stmtrev = $mysqli->prepare("SELECT * FROM store_reviews WHERE store_id=?");
$stmtrev->bind_param("i", $_GET['storeid']);
$stmtrev->execute();
$revrows = $stmtrev->get_result();
$stmtrev->close();
$total=0;
while ($stars = $revrows->fetch_assoc())
{
$count = ($total + $stars['rev_star']);
}
$count/count($revrows->fetch_assoc());
?>
Can anyone explain what's wrong and what could be done?