使用 PHP/MySQL 计算百分比 [英] Using PHP/MySQL to Calculate Percentages

查看:62
本文介绍了使用 PHP/MySQL 计算百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算完成在线成绩册家庭作业的学生人数,但我无法弄清楚代码......

I'm trying to calculate the number of students who've completed an their homework for an online gradebook, and I can't figure the code out...

    // SELECT THE TOTAL
$gettotal = "SELECT enroll FROM student_course WHERE classID = $classID";
$showtotal = @mysqli_query ($dbc, $gettotal); // Run the query.

//THIS IS LINE 108
$numtotal = mysql_num_rows($showtotal);

echo '$numtotal';

// SELECT THOSE PASSED
$getpassed = "SELECT entry FROM grades WHERE classID = $classID AND test_result >= 80";
$showpassed = @mysqli_query ($dbc, $getpassed); // Run the query.

$numpassed = mysql_num_rows($showpassed);

//THIS IS LINE 117
echo '$numpassed';

        // PERFORM THE PERCENTAGE FUNCTION

        function percent($numpassed, $numtotal) {
            $count1 = $numpassed / $numtotal;
            $count2 = $count1 * 100;
            $count = number_format($count2, 0);
            echo $count;
        }

//THIS IS LINE 124
        percent($numpassed, $numtotal);

我收到以下错误:

警告:mysql_num_rows():在第 108 行提供的参数不是有效的 MySQL 结果资源$numtotal警告:mysql_num_rows():在第 117 行提供的参数不是有效的 MySQL 结果资源$numpassed警告:第 124 行被零除0

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 108 $numtotal Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 117 $numpassed Warning: Division by zero in on line 124 0

推荐答案

好的 - 虽然我感谢大家关心删除 @ ... 没有人注意到问题是使用 mysqli_query 和然后 mysql_num_rows.需要改为mysqli_num_rows.

Okay - while I thank everyone for their concern removing the @ ... no one noticed that the problem was using mysqli_query and then mysql_num_rows. It needed to be changed to mysqli_num_rows.

谢谢:)

这篇关于使用 PHP/MySQL 计算百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆