Jump to content

DROP TABLE IF EXISTS


Donovan

Recommended Posts

This bit of code is not working in my script. 

//Drop Import table
$sql = "DROP TABLE IF EXISTS ".$prefix."_tl_session_grade_import";
$result = $db->sql_query($sql);	
if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");} 

 

I do not get any $results echoed for any mysql_error(), and the table _tl_session_grade_import does not get dropped.

 

Here is the code in it's entirety.

 

<?php

if(!defined('TL_ADMIN')) { die("Illegal Access Detected!!!"); }
global $prefix;
$modname = "Team_Learning";
include("header.php");
TLAdminMenu();

$Session_ID = $_POST['Session_ID'];
/*
//Check if already imported
$checkSession = $db->sql_query("SELECT * FROM ".$prefix."_tl_session_grades WHERE Session_ID = '$Session_ID' AND IRAT_Grade != 0");
$Session_total = $db->sql_numrows($checkSession);
//We have Session_ID's for IRAT's that have already been imported.
if ($Session_total > 0) {
OpenTable();
echo"<tr><td>IRAT grades for this Session have already been imported.</td></tr>";
echo"<tr><td>You can edit individual IRAT grades <a href='".$admin_file.".php?op=TLViewIratGrades&Session_ID=$Session_ID'>Here!</a></td></tr>";
Closetable();
exit();
}
*/

//Get the academic year
$Get_Academic_Year = $db->sql_query("SELECT Academic_Year FROM ".$prefix."_tl_config");  
while ($info = $db->sql_fetchrow($Get_Academic_Year)) {
	$Academic_Year = $info['Academic_Year']; 
	}

//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)");

//Drop Import table
$sql = "DROP TABLE IF EXISTS ".$prefix."_tl_session_grade_import";
$result = $db->sql_query($sql);	
if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");} 
     
header("Location: ".$admin_file.".php?op=TLViewIratGrades&Session_ID=$Session_ID");
}
?>

Link to comment
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.