Jump to content

Recommended Posts

I have about 104 records in the _tl_session_grade_import table and 418 records in the _tl_students table.  I want to compare a.StudentID != b.U_Account and echo number of records were I have a match.  This is for testing so I do not import the records with inaccurate data.  For some reason I echo 43372 records, but I don't know why.

 

I should only have 4 records where the StudentID does not match U_Account.

 

I commented out using Session_ID to try an identify where the error is.

 

//Check valid Students UID's and compare to the imported table
$checkUID = $db->sql_query("SELECT a.StudentID FROM ".$prefix."_tl_session_grade_import a
JOIN ".$prefix."_tl_students b 
WHERE a.StudentID != b.U_Account");
//AND a.Session_ID = '$Session_ID'");
//WHERE a.Session_ID = '$Session_ID'");

$error_total = $db->sql_numrows($checkUID);

//for testing
echo"$error_total";
exit();
//We have unmatched UID's!
if ($error_total > 0) {
OpenTable();
echo"<tr><td>There are errors in the IRAT imported table.  These need to be fixed before writing to the grades table.  Ensure all student UID's match for all current students already in the system.</td></tr>";
echo"<tr><td><input type=\"button\" value=\"Back\" onClick=\"history.go(-1)\"></td></tr>";
Closetable();
}else{
//No errors detected so import IRAT grades from _tl_session_grade_import into _tl_session_grades table.

 

The imported data comes from a scantron.  I need to cleanse the data before it gets written to the grades table.

Link to comment
https://forums.phpfreaks.com/topic/84512-testing-if-value-0/
Share on other sites

Try echoing the query out to see if all the values are what you expect.

<?php
$query = "
    SELECT a.StudentID FROM ".$prefix."_tl_session_grade_import a
    JOIN ".$prefix."_tl_students b 
    WHERE a.StudentID != b.U_Account");
    //AND a.Session_ID = '$Session_ID'");
    //WHERE a.Session_ID = '$Session_ID'"

echo $query;

$checkUID = $db->sql_query($query);
?>

Link to comment
https://forums.phpfreaks.com/topic/84512-testing-if-value-0/#findComment-430586
Share on other sites

to find students without a matching U_Account record

 

SELECT a.StudentID

FROM ".$prefix."_tl_session_grade_import a

LEFT JOIN ".$prefix."_tl_students b ON a.StudentID = b.U_Account

WHERE b.U_Account IS NULL"

 

Thanks

 

This gives me back the number of matched records.  Wouldn't the next bit of code stop the script if I had $error_total greater than 0?

 

//Check valid Students UID's and compare to the imported table
$checkUID = $db->sql_query("SELECT a.StudentID FROM ".$prefix."_tl_session_grade_import a
LEFT JOIN ".$prefix."_tl_students b ON a.StudentID = b.U_Account
WHERE b.U_Account IS NULL");
//AND a.Session_ID = '$Session_ID'");
//WHERE a.Session_ID = '$Session_ID'");

$error_total = $db->sql_numrows($checkUID);

//We have unmatched UID's!
if ($error_total > 0) 
{
OpenTable();
echo"<tr><td>There are errors in the IRAT imported table.  These need to be fixed before writing to the grades table.  Ensure all student UID's match for all current students already in the system.</td></tr>";
echo"<tr><td><input type=\"button\" value=\"Back\" onClick=\"history.go(-1)\"></td></tr>";
Closetable();
}else{
//No errors detected so import IRAT grades from _tl_session_grade_import into _tl_session_grades table.

$sql = ("INSERT INTO ".$prefix."_tl_session_grades (Session_ID, SOMS_KEY, UID, Group_ID, IRAT_Grade)
(SELECT a.Session_ID, b.SOMS_KEY, a.StudentID, c.Group_ID, a.Total_Percent FROM ".$prefix."_tl_session_grade_import a
JOIN ".$prefix."_tl_students b ON (a.StudentID = b.U_Account)
JOIN ".$prefix."_tl_group_students c ON (b.SOMS_KEY = c.SOMS_KEY)
JOIN ".$prefix."_tl_session d
WHERE a.Session_ID = d.Session_ID)");
$result = $db->sql_query($sql);
if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");} 

//Get the academic year and update table
$Get_Academic_Year = $db->sql_query("UPDATE ".$prefix."_tl_session_grades SET Academic_Year = (SELECT Academic_Year FROM ".$prefix."_tl_config)"); 
}     
header("Location: ".$admin_file.".php?op=TLViewIratGrades&Session_ID=$Session_ID");

 

The INSERT never happens, nor does the ...

 

echo"<tr><td>There are errors in the IRAT imported table.  These need to be fixed before writing to the grades table.  Ensure all student UID's match for all current students already in the system.</td></tr>";
echo"<tr><td><input type=\"button\" value=\"Back\" onClick=\"history.go(-1)\"></td></tr>";

 

Instead I get sent to

 

header("Location: ".$admin_file.".php?op=TLViewIratGrades&Session_ID=$Session_ID");

 

Which displays nothing since the _tl_session_grades is still empty.

 

Link to comment
https://forums.phpfreaks.com/topic/84512-testing-if-value-0/#findComment-430598
Share on other sites

I can't figure this out.

 

$error_total = 5

 

It says that when I echo it out.

 

Yet this

 

 if ( $error_total > 0 ) {
OpenTable();
echo"<tr><td>There are errors in the IRAT imported table.  These need to be fixed before writing to the grades table.  Ensure all student UID's match for all current students already in the system.</td></tr>";
echo"<tr><td><input type=\"button\" value=\"Back\" onClick=\"history.go(-1)\"></td></tr>";
Closetable();

 

does nothing

 

 

Link to comment
https://forums.phpfreaks.com/topic/84512-testing-if-value-0/#findComment-430684
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.