<?php
$q2 = "SELECT SUM(crd)
FROM coe_courses
INNER JOIN student_record ON coe_courses.course_number =
student_record.course_number WHERE student_record.id =".$_SESSION['user_id'] ;
$result = mysqli_query($con , $q2 ) ;
if($row = mysqli_fetch_array($result)){
echo $row["SUM(crd)"];
}
$q2a = "SELECT SUM(points) FROM student_record where student_record.id =".$_SESSION['user_id'] ;
$result = mysqli_query($con , $q2a ) ;
if($row = mysqli_fetch_array($result)){
echo $row["SUM(points)"];
}
?>
我编写了这段代码但是如何在这段代码的末尾对这些语句进行除法
echo $row["SUM(crd)"] /$row["SUM(points)"];
答案 0 :(得分:0)
首先,您应该将这两个值存储在不同的变量中,因为根据您的代码,您将覆盖$ row变量,因此您将只得到第二个结果。之后你就可以做到这一点。
if(!empty($b)) {
$ans = (int) ($a/$b);
}