The code below works great, but it is printing Resource ID #... to the screen which is becoming a problem. I did some reading and this seems to be related to the mysql_fetch commands, and it seems like those need to be slightly re-written to ensure nothing prints to the screen, but I have no idea how to rewrite it. Can someone help?
function sync_credit_type()
{
global $CFG;
$userid=$SESSION['USER']->id;
$temp=$SESSION['USER']->idnumber;
if ($CFG->enrol_dbtype=="mssql")
{
$con1 = mssql_connect($CFG->enrol_dbhost, $CFG->enrol_dbuser, $CFG->enrol_dbpass);
if(!con1)
{
echo "Something went wrong while connecting to MSSQL";
}
mssql_select_db($CFG->enrol_dbname, $con1);
if($userid == ''|$userid == 0)
{
$query_in=mssql_query("SELECT ".$CFG->enrol_remotecoursefield.",".$CFG->enrol_remoteuserfield.",".$CFG->credit_type." FROM ".$CFG->enrol_dbtable);
}
else
{
$query_in=mssql_query("SELECT ".$CFG->enrol_remotecoursefield.",".$CFG->enrol_remoteuserfield.",".$CFG->credit_type." FROM ".$CFG->enrol_dbtable." where ".$CFG->enrol_remoteuserfield." = '".$temp."'");
}
//$res=mysql_fetch_array($query_in);
$con2 = mysql_connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass) or die("error in connection".mysql_error());
if(!$con2)
{
echo "Something went wrong while connecting to MySQL";
}
mysql_select_db($CFG->dbname, $con2) or die("error in db selection".mysql_error());
while($res=mssql_fetch_array($query_in))
{
$Credit_type = $res[$CFG->credit_type];
$coursefield = $res[$CFG->enrol_remotecoursefield];
$userfield = $res[$CFG->enrol_remoteuserfield];
mysql_select_db($CFG->dbname, $con2) or die("error in db selection".mysql_error());
echo $cou_id=mysql_query("select id from mdl_course where idnumber='".$coursefield."'");
$coid=mysql_fetch_row($cou_id);
$courseid=$coid[0];
if ($courseid > 0) {
$result = mysql_query("select distinct id from mdl_user where idnumber = '".$userfield."'");
$userId_row = mysql_fetch_row($result);
$user_Id = $userId_row[0];
$check_data = mysql_query("SELECT * FROM `mdl_grade_transcript` WHERE UserID='".$user_Id."' AND CourseID='".$courseid."'");
if(mysql_num_rows($result) >0)
{
if(mysql_num_rows($check_data) >0)
{
$sql1=mysql_query("UPDATE `mdl_grade_transcript` SET
Credit_Type ='".$Credit_type."' ,
Timemodified = '".time()."' WHERE UserID = '".$user_Id."' AND CourseID='".$courseid."'");
}else
{
$sql2=mysql_query("INSERT INTO `mdl_grade_transcript` (
`UserID` ,
`CourseID` ,
`Credit_Type` ,
`Timemodified` ,
`modifierid`
)
VALUES (
'".$user_Id."', '".$courseid."', '".$Credit_type."', '".time()."', '1')") or die(mysql_error());
}
}
else {
echo "course mismatch";
}
}
}