title: multiple queries inside while loop is slowing down the script
body: <p>multiple queries inside while loop is really slowing down the script.. what actually i want is list of engineers suppose if it is 20..that particular engineer has done how many repairs..
  my code is as follows</p>
  
  <pre><code>&lt;?php
      while($row=mysql_fetch_row($total_repairs)){
          // print_r($row);
          //echo "SELECT COUNT( CustomerFeed.technical ) as tech_sat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.technical in (1,2)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'";
          $engineer=$row[0];
          //$engineer=$row['empName'];
          $location=$row['locationName'];
          $repairs=mysql_query("select count(ackNo) as tot from tblRepairQueue where assignedTo='".$engineer."' and month(ClosedAt)='".$month."' and YEAR(ClosedAt)='".$year."'");
          $tot_repairs=mysql_fetch_array($repairs);
          $feedback_rec=mysql_query("select count(callStatus) as feedback from ContactCenter where callStatus='Close' and assignedTo='".$engineer."'  and month(ClosedAt)='".$month."' and YEAR(ClosedAt)='".$year."' ");
          $tot_feedback=mysql_fetch_array($feedback_rec);
          $techsat=mysql_query("SELECT COUNT( CustomerFeed.technical ) as tech_sat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.technical in (1,2)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'  and YEAR(ContactCenter.ClosedAt)='".$year."' ");
          $tech_sat=mysql_fetch_array($techsat);
          $techdsat=mysql_query("SELECT COUNT( CustomerFeed.technical ) as tech_dsat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.technical in (4,5)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'   and YEAR(ContactCenter.ClosedAt)='".$year."' ");
          $tech_dsat=mysql_fetch_array($techdsat);
          $profsat=mysql_query("SELECT COUNT( CustomerFeed.prof ) as prof_sat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.prof in (1,2)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'   and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $prof_sat=mysql_fetch_array($profsat);
          $profdsat=mysql_query("SELECT COUNT( CustomerFeed.prof ) as prof_dsat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.prof in (4,5)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and  ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'   and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $prof_dsat=mysql_fetch_array($profdsat);
          /*$ressat=mysql_query("SELECT COUNT( CustomerFeed.res ) as res_sat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.res in (1,2)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'  and YEAR(ContactCenter.ClosedAt)='".$year."' ");
          $res_sat=mysql_fetch_array($ressat);
          $resdsat=mysql_query("SELECT COUNT( CustomerFeed.res ) as res_dsat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.res in (4,5)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'   and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $res_dsat=mysql_fetch_array($resdsat);*/
          $qttysat=mysql_query("SELECT COUNT( CustomerFeed.qtty ) as qtty_sat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.qtty in (1,2)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'   and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $qtty_sat=mysql_fetch_array($qttysat);
          $qttydsat=mysql_query("SELECT COUNT( CustomerFeed.qtty ) as qtty_dsat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.qtty in (4,5)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'   and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $qtty_dsat=mysql_fetch_array($qttydsat);
          /* $timesat=mysql_query("SELECT COUNT( CustomerFeed.tim ) as time_sat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.tim in (1,2)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'   and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $time_sat=mysql_fetch_array($timesat);
          $timedsat=mysql_query("SELECT COUNT( CustomerFeed.tim ) as time_dsat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.tim in (4,5)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'  and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $time_dsat=mysql_fetch_array($timedsat);*/
          $overallsat=mysql_query("SELECT COUNT( CustomerFeed.overall ) as overall_sat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.overall in (1,2)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.callStatus='Close' and ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'  and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $overall_sat=mysql_fetch_array($overallsat);
          $overalldsat=mysql_query("SELECT COUNT( CustomerFeed.overall ) as overall_dsat FROM ContactCenter, CustomerFeed WHERE CustomerFeed.overall in (4,5)  AND CustomerFeed.callId = ContactCenter.callId AND ContactCenter.assignedTo = '".$engineer."' and month(ContactCenter.ClosedAt)='".$month."'  and YEAR(ContactCenter.ClosedAt)='".$year."'");
          $overall_dsat=mysql_fetch_array($overalldsat);
      ?&gt;
          &lt;tr align="center" bgcolor="#F8F8F8"&gt;
          &lt;td align="left"&gt;&lt;?=$engineer?&gt;&lt;/td&gt;
          &lt;!--&lt;td&gt;&lt;?=$location?&gt;&lt;/td&gt;--&gt;
          &lt;td&gt;&lt;? echo ($tot_repairs['tot']!='0') ? $tot_repairs['tot'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo ($tot_feedback['feedback']!='0') ? $tot_feedback['feedback'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($tot_feedback['feedback']/$tot_repairs['tot'])*100);?&gt;&lt;/td&gt;
  
          &lt;td&gt;&lt;? echo ($tech_sat['tech_sat']!='0') ? $tech_sat['tech_sat'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($tech_sat['tech_sat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
  
          &lt;td&gt;&lt;? echo ($tech_dsat['tech_dsat']!='0') ? $tech_dsat['tech_dsat'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($tech_dsat['tech_dsat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
  
          &lt;td&gt;&lt;? echo ($prof_sat['prof_sat']!='0') ? $prof_sat['prof_sat'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($prof_sat['prof_sat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
  
          &lt;td&gt;&lt;? echo ($prof_dsat['prof_dsat']!='0') ? $prof_dsat['prof_dsat'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($prof_dsat['prof_dsat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
  
          &lt;!-- &lt;td&gt;&lt;?=$res_sat['res_sat']?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($res_sat['res_sat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?=$res_dsat['res_dsat']?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($res_dsat['res_dsat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;--&gt;
  
  
          &lt;td&gt;&lt;? echo ($qtty_sat['qtty_sat']!='0') ? $qtty_sat['qtty_sat'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($qtty_sat['qtty_sat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
  
          &lt;td&gt;&lt;? echo ($qtty_dsat['qtty_dsat']!='0') ? $qtty_dsat['qtty_dsat'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($qtty_dsat['qtty_dsat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
  
          &lt;!--&lt;td&gt;&lt;?=$time_sat['time_sat']?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($time_sat['time_sat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?=$time_dsat['time_dsat']?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($time_dsat['time_dsat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;--&gt;
  
          &lt;td&gt;&lt;? echo ($overall_sat['overall_sat']!='0') ? $overall_sat['overall_sat'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($overall_sat['overall_sat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
  
          &lt;td&gt;&lt;? echo ($overall_dsat['overall_dsat']!='0') ? $overall_dsat['overall_dsat'] : "-";?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;? echo round(($overall_dsat['overall_dsat']/$tot_feedback['feedback'])*100); ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
  &lt;?php
      }
  </code></pre>