php - Combine Nested While Statement -


i have nested while statement gives results need inefficient , takes forever run? thoughts on how these combined?

i first create temporary table data need larger table called student grades. students , course names because want group these each report. each student scores each assignment. want average of of last 3 assignments each particular learning outcome id.

//mysql query create temp table $qrytmp = "create temporary table if not exists tmp (select     studentsisid,coursename,assessmenttitle,studentname,outcomescore,recordid,learningoutcomeid,learningoutcomename,assessmentid studentgrades  studentsisid '$studentid' , coursename '$coursename')"; mysql_query($qrytmp);  //mysql query coursename , student name $qrycourse = "select studentsisid,coursename,studentname tmp studentsisid '$studentid' , coursename '$coursename' group studentsisid,coursename order studentname,coursename"; $resultcourse=mysql_query($qrycourse); while ($rowcourse = mysql_fetch_assoc($resultcourse)) {     $studentid = $rowcourse['studentsisid'];     $name = $rowcourse['studentname'];     $coursename = $rowcourse['coursename'];  //mysql query learning outcome id $qrylid ="select outcomescore,learningoutcomeid,count(recordid) assessmentcount tmp  studentsisid = '$studentid' , coursename='$coursename' group studentsisid,coursename, learningoutcomeid  order studentname, coursename"; $resultlid=mysql_query($qrylid);  while ($rowlid = mysql_fetch_assoc($resultlid)) {     $learningoutcomeid = (int)$rowlid['learningoutcomeid'];     $assessmentcount = (int)$rowlid['assessmentcount'];  //mysql query recent 3 $qryrecent3 = "select avg(outcomescore) recentscoreavg                   (select outcomescore tmp          studentsisid='$studentid' , coursename='$coursename' , learningoutcomeid='$learningoutcomeid'          order assessmentid desc limit 3) r";    $resultrecent3=mysql_query($qryrecent3);          while ($rowrecent3 = mysql_fetch_assoc($resultrecent3)) {             $recentscoreavg = number_format($rowrecent3['recentscoreavg'], 1);             $assessmentcount = $rowrecent3['recentover3'];      } } } 


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -