$score = 50
$total = 500
mysqli_query($conn,"UPDATE student_quiz SET `grade` = ".$score." out of ".$total."')
因此,目前这将在数据库中存储"500分之50",但我想它做的是存储$score和$total的商,因此它应该是"0.1",而不是"500分50".
当我显示它时,我如何将其作为百分比,这样当我回显$grade时,它将变为"10%",而不是"0.1".目前,这是我获取和显示分数的方式.
$query1 = mysqli_query($conn,"select * from student_class_quiz where class_quiz_id = '$id' and student_id = '$session_id'")or die(mysqli_error());
$row1 = mysqli_fetch_array($query1);
$grade = $row1['grade'];
<?php echo $grade; ?>
用`$score/$total计算商.
要将其显示为百分比,请乘以100.