Jump to content

SELECT (value / value) * variable) AS variable


Donovan

Recommended Posts

Somebody help me with this query.  I have a raw score from a test.  I get the number of questions for this test and then try to update the grade.

 

This gets the number of questions that were on the test.

 

$getnumquestions = $db->sql_query("SELECT num_quest_irat FROM ".$prefix."_tl_session WHERE Session_ID = '$Session_ID'");
while($info = $db->sql_fetchrow($getnumquestions)) {
$NumQuestions = $info['num_quest_irat'];
}  

 

The next code is trying to update the table and set a value for IRAT_Grade.

 

$updateIRAT_Grade = $db->sql_query("UPDATE ".$prefix."_tl_session_grades sg
JOIN ".$prefix."_tl_session s
SET IRAT_Grade = (SELECT ((IRAT_Raw / $NumQuestions) * 100) AS IRATGrade)
WHERE sg.Session_ID = s.Session_ID");
if (!$updateIRAT_Grade) {
	echo("<p>Error performing query: " . mysql_error() . "</p>");
	exit();   
	}

 

Currently I am getting an error:

 

Error performing query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') * 100) AS IRATGrade) WHERE sg.Session_ID = s.Session_ID' at line 3

Link to comment
Share on other sites

Also I think I can have multple SET commands in one query.

 

True?

 

$updateGrade = $db->sql_query("UPDATE ".$prefix."_tl_session_grades sg
JOIN ".$prefix."_tl_session s
SET IRAT_Grade = (SELECT ((IRAT_Raw / $NumQuestions) * 100) AS IRATGrade)
SET GRAT_Grade = (SELECT ((GRAT_Raw / $NumQuestions) * 100) AS GRATGrade)
SET AppEx_Grade = (SELECT ((Appex_Raw / $NumQuestions) * 100) AS AppexGrade)
WHERE sg.Session_ID = s.Session_ID");
if (!$updateGrade) {
echo("<p>Error performing query: " . mysql_error() . "</p>");	
exit(); 

 

}

Link to comment
Share on other sites

I'm not following you.  Your reply is to vague.

 

Do you mean something like this?

 

$updateGrade = $db->sql_query("UPDATE ".$prefix."_tl_session_grades
SET IRAT_Grade = (SELECT ((IRAT_Raw / $IratQuestions) * 100) AS IRATGrade),
SET GRAT_Grade = (SELECT ((GRAT_Raw / $GratQuestions) * 100) AS GRATGrade),
SET AppEx_Grade = (SELECT ((Appex_Raw / $AppExQuestions) * 100) AS AppexGrade)
WHERE Session_ID = '$Session_ID'");
if (!$updateGrade) {
echo("<p>Error performing query: " . mysql_error() . "</p>");	
exit();
}

Link to comment
Share on other sites

No, I mean:

updateGrade = $db->sql_query("UPDATE ".$prefix."_tl_session_grades
SET IRAT_Grade = (SELECT ((IRAT_Raw / $IratQuestions) * 100) AS IRATGrade),
GRAT_Grade = (SELECT ((GRAT_Raw / $GratQuestions) * 100) AS GRATGrade),
AppEx_Grade = (SELECT ((Appex_Raw / $AppExQuestions) * 100) AS AppexGrade)
WHERE Session_ID = '$Session_ID'");
if (!$updateGrade) {
echo("<p>Error performing query: " . mysql_error() . "</p>");	
exit();
}

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.