简体   繁体   中英

php passing array between pages

I have two php pages running in Moodle.

index.php and lib.php

there is an include statement inside index.php pointing to lib.php.

inside index.php I have this function call;

$users = get_mentor_users2($fromdate, $todate);

when I call the function, which executes in lib.php, I get a blank webpage.

The function in lib.php is:

function get_mentor_users2($fromdate = 0, $todate = 0){

//global $USER, $CFG;

/*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'); ////}

$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%'";

if($datesql = generate_sql_range2($fromdate, $todate, 'g.timemodified')) { $sql .= " AND $datesql"; }

//get all users who graded //echo $sql.'
'; //$users = $DB->get_records_sql($sql);

//foreach

//~ $tmpdata = array();
//~ $tmpdata = $DB->get_records_sql($sql); //~ return array($tmpdata);

//return $DB->get_records($sql, array $params=null, $limitfrom=0, $limitnum=0);

$arr= array(); return $arr=$DB->get_records_sql($sql); //return $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 = "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%'";

$data = array();

$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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM