Donovan Posted March 18, 2008 Share Posted March 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/96711-select-value-value-variable-as-variable/ Share on other sites More sharing options...
Donovan Posted March 18, 2008 Author Share Posted March 18, 2008 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/96711-select-value-value-variable-as-variable/#findComment-494881 Share on other sites More sharing options...
fenway Posted March 18, 2008 Share Posted March 18, 2008 You can't... separate columns by commas. Quote Link to comment https://forums.phpfreaks.com/topic/96711-select-value-value-variable-as-variable/#findComment-494885 Share on other sites More sharing options...
Donovan Posted March 18, 2008 Author Share Posted March 18, 2008 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/96711-select-value-value-variable-as-variable/#findComment-494907 Share on other sites More sharing options...
fenway Posted March 18, 2008 Share Posted March 18, 2008 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/96711-select-value-value-variable-as-variable/#findComment-494920 Share on other sites More sharing options...
Donovan Posted March 18, 2008 Author Share Posted March 18, 2008 Thanks. Mark solved. Quote Link to comment https://forums.phpfreaks.com/topic/96711-select-value-value-variable-as-variable/#findComment-495106 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.