我使用moodle和函数get_course_students来获取学生列表
$students = get_course_students($course->id, 'lastname');
echo print_r($students);
输出:
Array (
[4382] => stdClass Object (
[confirmed] => 1
, [username] => test22
, [firstname] => test
, [lastname] => 22
, [maildisplay] => 2
, [mailformat] => 1
, [maildigest] => 0
, [email] => test22@test.couk
, [city] => test
, [country] => GB
, [picture] => 1
, [idnumber] =>
, [department] =>
, [institution] =>
, [emailstop] => 0
, [lang] => en_utf8
, [timezone] => 99
, [lastaccess] =>
, [id] => 4382 )
[518] => stdClass Object (
, [confirmed] => 1
, [username] => st999999
, [firstname] => st999999
, [lastname] => account
, [maildisplay] => 2
, [mailformat] => 1
, [maildigest] => 0
, [email] => st999999@test.co.uk
, [city] =>
, [country] => GB
, [picture] => 1
, [idnumber] =>
, [department] =>
, [institution] =>
, [emailstop] => 0
, [lang] => en_utf8
, [timezone] => 99
, [lastaccess] => 1315843176
, [id] => 518
)
)
然后,我想计算一个表中的记录数量,但只计算当前分配给该课程的学生。
$totalreportscountrecords = count_records_sql("SELECT COUNT(*) FROM mdl_ilp_reports WHERE course = $course->id AND user = $students");
如何修改SQL语句来执行此操作?任何帮助将不胜感激。
答案 0 :(得分:0)
我猜,你正在使用自定义表。我在Moodle-1.9或Moodle-2.0中找不到表名* _reports。
但是,这是一个可能的解决方案:
如果get_course_students为您提供用户ID,则可以使用
WHERE course = $course->id AND user IN (555,556)
如果get_course_students返回一组值,您可以使用PHP的implode来获取逗号分隔的userid列表。
希望这有帮助。