私はメディアの製品と同等の星の評価のシステムを持っており、全体どのように製品の評価システムの正しい割合を計算する?
例:
0.5
から1
- 1.5
- 2
から2.5
- 3
から3.5
- 4
から4.5
- 5
2つのデータを中と全体で正しく取り込み、両方の値を合計します。
次の相談から:
//we define in a variable the id of the product valued by the valuation system
$id_product = 1;
//we obtain an average and integer value equivalent to 4.5 and 5
$stmt = $con->prepare("SELECT SUM(rating) as total FROM ratings WHERE id_product=? AND rating in(4.5,5)");
$stmt->bind_param("i",$id_product);
$stmt->execute();
$stmt->bind_result($sum);
while ($stmt->fetch()) {
echo $sum;
}
//we obtain an average and integer value equivalent to 3.5 and 4
$stmt = $con->prepare("SELECT SUM(rating) as total FROM ratings WHERE id_product=? AND rating in(3.5,4)");
$stmt->bind_param("i",$id_product);
$stmt->execute();
$stmt->bind_result($sum);
while ($stmt->fetch()) {
echo $sum;
}
//we obtain an average and integer value equivalent to 2.5 and 3
$stmt = $con->prepare("SELECT SUM(rating) as total FROM ratings WHERE id_product=? AND rating in(2.5,3)");
$stmt->bind_param("i",$id_product);
$stmt->execute();
$stmt->bind_result($sum);
while ($stmt->fetch()) {
echo $sum;
}
//we obtain an average and integer value equivalent to 1.5 and 2
$stmt = $con->prepare("SELECT SUM(rating) as total FROM ratings WHERE id_product=? AND rating in(1.5,2)");
$stmt->bind_param("i",$id_product);
$stmt->execute();
$stmt->bind_result($sum);
while ($stmt->fetch()) {
echo $sum;
}
//we obtain an average and integer value equivalent to 0.5 and 1
$stmt = $con->prepare("SELECT SUM(rating) as total FROM ratings WHERE id_product=? AND rating in(0.5,1)");
$stmt->bind_param("i",$id_product);
$stmt->execute();
$stmt->bind_result($sum);
while ($stmt->fetch()) {
echo $sum;
}
今、私の質問はどのように私が正しく割合でデータを計算し、以下の画像のような結果を得ることができます:
「相撲」? 「苦闘する」のように? – Strawberry
@Strawberryはそれほど深刻ではありません正書法上のエラーは「合計」 –