[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sheflug] php / moodle problem
Dear All
I'm not sure if I'm missing something obvious, but I've hit a brick
wall. I'm writing a set of php / shell scripts to import pupils,
teachers and courses from SIMS into moodle, and I've hit a php problem I
can't get my head round. There's a set of csv data in a text file
(pupil_enrollment.txt)
The top ten lines look like this
16392,Reg. :: 11RY
16392,Vocational :: 11Vo/Vo3
16392,English :: 11ac/En2
16392,Maths :: 11ac/Ma3
16392,P.E. :: 11ac/Pe1
16392,Science :: 11ac/Sc4
16392,Health&Soc :: 11c/Hs1
16392,R.E. :: 11c/Re1
16392,Technology :: 11c/Te3
16392,11b.. :: CLS
They correspond to a pupil username (which is already in moodle in the
mdl_user table) and a course id (also in moodle in mdl_course table).
The corresponding php script goes through the file and should generate a
sql insert query for each line of the data file. So far all I'm trying
to do is to get a course id for each course (second column in the data
file). The php script so far is
<?php
//Script to enrol pupils on courses using data exported from SIMS
// The courses should already have been created and the pupils added
as moodle users
require_once("../../config.php");
mysql_connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass);
$input_file="pupil_enrollment.txt";
$arr_pupils=file ($input_file);
//Iterate through each data entry and get a pupil id and course id for
each entry
foreach ($arr_pupils as $str_details)
{
//Get a course id
$arr_details=explode(",",$str_details);
$sql="SELECT id FROM mdl_course WHERE idnumber='".$arr_details[1]."'
LIMIT 1";
$result=mysql_query($sql);
$arr=mysql_fetch_array($result);
print_r ($arr);
}
?>
Everything's fine until the line near the end
$arr=mysql_fetch_array($result)
which doesn't work. Everything else does. I iterate through the file and
generate sql queries. These work either as standalone queries in a php
script or run through phpmyadmin. The line
$result=mysql_query($sql)
works fine and returns a result identifier to a mysql result (checked
with get_resource_type()). The line
$arr=mysql_fetch_array($result)
returns false and I've no idea why. I don't get any error messages at
all, just a white screen. So far I've run various other scripts that
manipulate the database to create courses, assign teachers to them and
upload students using the same connection details all with no problems,
but a white screen at this stage has left me scratching my head. I
might just have been staring at it too long. If anyone can suggest
anything I'd be very grateful
Thanks
David Willington
___________________________________________________________________
Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html
GNU the choice of a complete generation.