我似乎无法让SQL IN运算符使用正确的moodle方式将变量输入到sql字符串中。
当我这样做时:
$activities = '('.$section->sequence.')';
$sql = "SELECT assign.name FROM {assign} assign
INNER JOIN {course_modules} cm
ON cm.instance = assign.id
INNER JOIN {modules} m
ON m.id = cm.module
WHERE m.name = 'assign' AND
cm.id IN ?";
$assignments = $DB->get_records_sql($sql, array($activities));
它不起作用,它说我的sql语法在IN运算符周围出错。
但是当我这样做时,它就有效了。 (不使用?)
$sql = "SELECT assign.name FROM {assign} assign
INNER JOIN {course_modules} cm
ON cm.instance = assign.id
INNER JOIN {modules} m
ON m.id = cm.module
WHERE m.name = 'assign' AND
cm.id IN ".$activities;
$assignments = $DB->get_records_sql($sql, null);
如何使用正确的moodle语法使其工作。即。 $assignments = $DB->get_records_sql($sql, array($activities));