[英]php passing array between pages
I have two php pages running in Moodle. 我有两个在Moodle中运行的php页面。
index.php and lib.php index.php和lib.php
there is an include statement inside index.php pointing to lib.php. 在index.php中有一个包含声明,指向lib.php。
inside index.php I have this function call; 在index.php里面,我有这个函数调用;
$users = get_mentor_users2($fromdate, $todate);
$ users = get_mentor_users2($ fromdate,$ todate);
when I call the function, which executes in lib.php, I get a blank webpage. 当我调用在lib.php中执行的函数时,我得到一个空白网页。
The function in lib.php is: lib.php中的函数是:
function get_mentor_users2($fromdate = 0, $todate = 0){
函数get_mentor_users2($ fromdate = 0,$ todate = 0){
//global $USER, $CFG;
//全局$ USER,$ CFG;
/*if(!$sumpcat = get_config('','sumname')){*/ ////if(!$sumpcat = get_config('','sumname')){ / if(!$sumpcat = "summative"){ / //echo $sumpcat;
/ * if(!$ sumpcat = get_config('','sumname')){* / //// if(!$ sumpcat = get_config('','sumname')){/ if(!$ sumpcat =“ summative “){ /// echo $ sumpcat; ////error('Summarative Grade Category Name not Specified 1.','conf.php');
//// error('未指定汇总成绩类别名称1。','conf.php'); ////}
////}
$sql = "SELECT DISTINCT u.id , u.firstname, u.lastname FROM {mdl_role_assignments ra}, {mdl_user u}, {mdl_course c}, {mdl_context cxt} WHERE ra.userid = u.id AND ra.contextid = cxt.id AND cxt.contextlevel =50 AND ( roleid =3 ) AND u.firstname LIKE '%mentor%'";
$ sql =“ SELECT DISTINCT u.id,u.firstname,u.lastname,来自{mdl_role_assignments ra},{mdl_user u},{mdl_course c},{mdl_context cxt},其中ra.userid = u.id和ra.contextid = cxt.id AND cxt.contextlevel = 50 AND(roleid = 3)AND u.firstlike LIKE'%mentor%'“;
if($datesql = generate_sql_range2($fromdate, $todate, 'g.timemodified')) { $sql .= " AND $datesql";
if($ datesql = generate_sql_range2($ fromdate,$ todate,'g.timemodified')){$ sql。=“ AND $ datesql”; }
}
//get all users who graded //echo $sql.'
//获取所有对// echo $ sql评分的用户。
';'; //$users = $DB->get_records_sql($sql);
// $ users = $ DB-> get_records_sql($ sql);
//foreach
// foreach
//~ $tmpdata = array();
//〜$ tmpdata = array();
//~ $tmpdata = $DB->get_records_sql($sql);//〜$ tmpdata = $ DB-> get_records_sql($ sql); //~ return array($tmpdata);
//〜返回数组($ tmpdata);
//return $DB->get_records($sql, array $params=null, $limitfrom=0, $limitnum=0);
//返回$ DB-> get_records($ sql,array $ params = null,$ limitfrom = 0,$ limitnum = 0);
$arr= array();
$ arr = array(); return $arr=$DB->get_records_sql($sql);
返回$ arr = $ DB-> get_records_sql($ sql); //return $sql;
//返回$ sql;
}
}
Now here is the really odd part. 现在这是真正奇怪的部分。 Like above it fails and the screen stays blank, but when I embed the sql query inside the index.php page it executes just fine.
像上面一样,它失败并且屏幕保持空白,但是当我将sql查询嵌入index.php页面中时,它执行得很好。
$sql = "SELECT DISTINCT u.id, u.firstname, u.lastname FROM mdl_role_assignments ra, mdl_user u, mdl_course c, mdl_context cxt WHERE ra.userid = u.id AND ra.contextid = cxt.id AND cxt.contextlevel =50 AND ( roleid =3 ) AND u.firstname LIKE '%mentor%'";
$ sql =“ SELECT DISTINCT u.id,u.firstname,u.lastname from mdl_role_assignments ra,mdl_user u,mdl_course c,mdl_context cxt,其中ra.userid = u.id AND ra.contextid = cxt.id AND cxt.contextlevel = 50 AND(Roleid = 3)AND u.firstlike LIKE'%mentor%'“;
$data = array();
$ data = array();
$data = $DB->get_records_sql($sql);
$ data = $ DB-> get_records_sql($ sql);
and the data is accessible. 并且数据是可访问的。
Does anyone have suggestions on how to fix this? 有人对如何解决此问题有建议吗?
you have ';
你有
';
before your commented code: 在您的注释代码之前:
'; //$users = $DB->get_records_sql($sql);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.