0

我做了很多计算来得到结果..因为我在 while 循环中运行所有查询,它需要很多时间来给出结果..它需要将近 1 分钟..任何人都可以建议我如何更快地获得结果..my代码如下

<table style="font-size:13px" width="150%" border="0" cellspacing="3" cellpadding="2">
<tr bgcolor="#0063F5" align="center" style="font-family: Helvetica; font-size:16px;color:#FFF; font-weight:bold;">
    <td colspan="29">Post Service Feedback Report For <?=$empLocationName ?> Location</td>
    </tr>
       <tr bgcolor="#D3E6F3" style=" color:#009; font-weight:bold" align="center">
    <td >Engineer Name</td>
    <!--<td>Location</td>-->
    <td>Total Repairs</td>
    <td>Total PSF Recieved</td>
    <td>Total PSF Recieved %</td>
    <td colspan="4">Technical Ability</td>
    <td  colspan="4">Professionalism</td>
    <td colspan="4">Quality of Repair</td>
    <td colspan="4">Overall Satisfaction</td>
  </tr>
  <tr bgcolor="#D3E6F3" style=" color:#009; font-weight:bold" align="center">
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>Sat</td>
  <td>Sat %</td>
  <td>D-Sat</td>
  <td>D-Sat %</td>
      <td>Sat</td>
  <td>Sat %</td>
  <td>D-Sat</td>
  <td>D-Sat %</td>

    <td>Sat</td>
  <td>Sat %</td>
  <td>D-Sat</td>
  <td>D-Sat %</td>

    <td>Sat</td>
  <td>Sat %</td>
  <td>D-Sat</td>
  <td>D-Sat %</td>  
  </tr>
  <?
  while($row=mysql_fetch_array($total_repairs)){

      $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);
      ?>
      <tr align="center" bgcolor="#F8F8F8">
      <td align="left"><?=$engineer?></td>

      <td><? if($tot_repairs['tot']!='0') { echo $tot_repairs['tot']; } else { echo "-"; }?></td>
      <td><? if($tot_feedback['feedback']!='0') { echo $tot_feedback['feedback']; } else { echo "-"; } ?></td>
      <td><? echo round(($tot_feedback['feedback']/$tot_repairs['tot'])*100);?></td>
      <td><? if($tech_sat['tech_sat']!='0') { echo $tech_sat['tech_sat']; } else echo "-";?></td>
      <td><? echo round(($tech_sat['tech_sat']/$tot_feedback['feedback'])*100); ?></td>
      <td><? if($tech_dsat['tech_dsat']!='0'){ echo $tech_dsat['tech_dsat']; } else echo "-";?></td>
      <td><? echo round(($tech_dsat['tech_dsat']/$tot_feedback['feedback'])*100); ?></td>
      <td><? if($prof_sat['prof_sat']!='0') { echo $prof_sat['prof_sat']; } else { echo "-"; }?></td>
      <td><? echo round(($prof_sat['prof_sat']/$tot_feedback['feedback'])*100); ?></td>
      <td><? if($prof_dsat['prof_dsat']!='0'){ echo $prof_dsat['prof_dsat']; } else  echo "-";?></td>
      <td><? echo round(($prof_dsat['prof_dsat']/$tot_feedback['feedback'])*100); ?></td>
      <!-- <td><?=$res_sat['res_sat']?></td>
      <td><? echo round(($res_sat['res_sat']/$tot_feedback['feedback'])*100); ?></td>
      <td><?=$res_dsat['res_dsat']?></td>
      <td><? echo round(($res_dsat['res_dsat']/$tot_feedback['feedback'])*100); ?></td>-->


      <td><? if($qtty_sat['qtty_sat']!='0'){ echo $qtty_sat['qtty_sat']; } else echo "-";?></td>
      <td><? echo round(($qtty_sat['qtty_sat']/$tot_feedback['feedback'])*100); ?></td>
       <td><? if($qtty_dsat['qtty_dsat']!='0') { echo $qtty_dsat['qtty_dsat'];} else echo "-";?></td>
      <td><? echo round(($qtty_dsat['qtty_dsat']/$tot_feedback['feedback'])*100); ?></td>
        <!--<td><?=$time_sat['time_sat']?></td>
      <td><? echo round(($time_sat['time_sat']/$tot_feedback['feedback'])*100); ?></td>
       <td><?=$time_dsat['time_dsat']?></td>
      <td><? echo round(($time_dsat['time_dsat']/$tot_feedback['feedback'])*100); ?></td>-->
      <td><? if($overall_sat['overall_sat']!='0'){ echo $overall_sat['overall_sat'];} else echo "-";?></td>
      <td><? echo round(($overall_sat['overall_sat']/$tot_feedback['feedback'])*100); ?></td>
      <td><? if($overall_dsat['overall_dsat']!='0'){ echo $overall_dsat['overall_dsat']; } else echo "-";?></td>
      <td><? echo round(($overall_dsat['overall_dsat']/$tot_feedback['feedback'])*100); ?></td>
      </tr>
 <? }
  ?>
</table>
4

2 回答 2

1

您可以使用 mysql_fetch_rows 代替 mysql_fetch_array。并对列应用索引。它将减少一些执行时间

于 2013-10-28T11:41:38.297 回答
0

您使用三元运算符来快速执行而不是 if else 并为单独的查询创建一个函数。

喜欢

于 2013-10-28T11:51:43.437 回答