Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php-mysql中的计算_Php_Mysql_Sql_Sum_Wamp - Fatal编程技术网

php-mysql中的计算

php-mysql中的计算,php,mysql,sql,sum,wamp,Php,Mysql,Sql,Sum,Wamp,我想计算每个学生的出勤率,它会显示每个学生的出勤率。下面是我的代码: <tbody> <?php $data = "SELECT SUM(studAtt_endTime - studAtt_startTime) FROM studentAttendance"; $result = $conn->query($data) or die ("Error: ".mysqli_error($conn)); //look

我想计算每个学生的出勤率,它会显示每个学生的出勤率。下面是我的代码:

<tbody>
    <?php
        $data = "SELECT SUM(studAtt_endTime - studAtt_startTime) FROM studentAttendance";   
        $result = $conn->query($data)
        or die ("Error: ".mysqli_error($conn)); //look if theres any error
            while($ser2=mysqli_fetch_array($result)) {
    ?>

    <?php
        $counter = 1;
        $data = "SELECT * FROM student INNER JOIN studentAttendance ON student.stud_matric=studentAttendance.student_stud_matric
                            INNER JOIN course ON course.course_code=studentAttendance.course_course_code
                            WHERE course_course_code LIKE '%$_GET[course]%'
                            GROUP BY student_stud_matric";
                $result = $conn->query($data)
                or die ("Error: ".mysqli_error($conn)); //look if theres any error      
                    while($ser=mysqli_fetch_array($result)) {
    ?>
                <tr>
                <td><center><?php echo $counter; 
                            $counter++; ?></center></td>
                <td><?php echo $ser["stud_matric"];?></td>
                <td><?php echo $ser["stud_name"];?></td>
                <td><?php
                        $a = $ser["course_contacthour"];
                        $b = "14";
                        $tch = ($a * 2 ) * $b; // tch= total contact hour in 14 week
                        echo number_format($ser2["SUM(studAtt_endTime - studAtt_startTime)"] / $tch * 100, 2);?></td>
                </tr>
                                    <?php
                                    }
                                    ?>
                                    <?php
                                    }
                                    ?>
                                </tbody>


与其编辑上面/下面的内容,让事情变得混乱,不如在这里发布一些其他内容。在没有看到模式的情况下,我不确定以下SQL是否正确,因为我不知道列
studatt_endtime
studatt_starttime
是否位于
studentattendence
表或
student
表中,因此您可能需要更改使用的前缀:

/* Now the `sum` is pertinent to the student whereas before it was not */
$data = "select *,
        sum( a.`studatt_endtime` - a.`studatt_starttime` ) as 'sum'
        from `student` s
        inner join `studentattendance` a on s.`stud_matric`=a.`student_stud_matric`
        inner join `course` c on c.`course_code`=a.`course_course_code`
        where a.`course_course_code` like '%".$course."%'
        group by a.`student_stud_matric`;";
另外,我不知道你到底想计算什么,数学对我来说从来都不是一个强项,但计算似乎有点含糊不清,因为没有附加到
BODMAS
计算方法,其中
BODMAS
代表
括号、顺序、除法、乘法、加法,减法
-因此计算可以通过以下不同方式进行:

$tot=number_format( $ser->sum / ( $tch * 100 ), 2 );
$alt_tot=number_format( ( $ser->sum / $tch ) * 100, 2 );

您有一个嵌套的sl查询,它使用
$result
——外部查询也使用它,这可能会导致问题。还有其他问题。为什么有两个问题?您在第二次查询中遗漏了参数名称周围的引号(即:
'%$\u GET[course]]'
应该是
'%{$\u GET['course']}%
,什么是
数字格式($ser2[“SUM(studAtt_endTime-studAtt_startTime)”]/$tch*100,2)
?我有两个查询,因为它不能由一个查询完成,或者它的me不能编写正确的查询。
number\u格式($ser2[“SUM(studAtt\u endTime-studAtt\u startTime)”/$tch*100,2)
是学生出勤率的计算。因此,我需要
SUM(studAtt\u endTime-studAtt\u startTime)
来自第一次查询。但是,显示的结果是根据所有学生的“总和(studAtt_endTime-studAtt_startTime)”计算得出的,而不是我想要的每个学生的总和。@ramraideries,这段代码我更理解tq!但我仍然无法正确计算。请参阅我在上面编辑的帖子@RamRaider上得到的信息
$tot=number_format( $ser->sum / ( $tch * 100 ), 2 );
$alt_tot=number_format( ( $ser->sum / $tch ) * 100, 2 );