Answer the question
In order to leave comments, you need to log in
How to display the received data with different 'id' in the same form?
Guys, tell me how to add a rating with the same 'id' for each product separately to different forms added via 'echo' by 'id'. The data 'stars_id' = '1' 'val' = '3.5' is passed through the $average1 variable for all products equally.
$result = "SELECT COUNT(stars_id), round(AVG(val),1) as average FROM stars GROUP BY stars_id";
$data = mysqli_query($connectBD, $result);
if (mysqli_num_rows($data)){
$row = mysqli_fetch_assoc($data);
$average1 = $row['average'];
echo $average1;
Answer the question
In order to leave comments, you need to log in
If I correctly understood the meaning of the stars_id field, then throw out COUNT and collect the result in an array:
$result = "SELECT stars_id, round(AVG(val),1) as average FROM stars GROUP BY stars_id";
$data = mysqli_query($connectBD, $result);
while ($row = mysql_fetch_assoc($data)) {
$stars[$row['stars_id']] = $row['average'];
}
select g.*, round(AVG(val),1) as stars FROM goods g, stars s WHERE stars_id=g.id GROUP BY g.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question