while 循环中的多个查询确实减慢了脚本的速度.. 我真正想要的是工程师列表,假设它是 20.. 那个特定的工程师做了多少次维修.. 我的代码如下
<?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);
?>
<tr align="center" bgcolor="#F8F8F8">
<td align="left"><?=$engineer?></td>
<!--<td><?=$location?></td>-->
<td><? echo ($tot_repairs['tot']!='0') ? $tot_repairs['tot'] : "-";?></td>
<td><? echo ($tot_feedback['feedback']!='0') ? $tot_feedback['feedback'] : "-";?></td>
<td><? echo round(($tot_feedback['feedback']/$tot_repairs['tot'])*100);?></td>
<td><? echo ($tech_sat['tech_sat']!='0') ? $tech_sat['tech_sat'] : "-";?></td>
<td><? echo round(($tech_sat['tech_sat']/$tot_feedback['feedback'])*100); ?></td>
<td><? echo ($tech_dsat['tech_dsat']!='0') ? $tech_dsat['tech_dsat'] : "-";?></td>
<td><? echo round(($tech_dsat['tech_dsat']/$tot_feedback['feedback'])*100); ?></td>
<td><? echo ($prof_sat['prof_sat']!='0') ? $prof_sat['prof_sat'] : "-";?></td>
<td><? echo round(($prof_sat['prof_sat']/$tot_feedback['feedback'])*100); ?></td>
<td><? echo ($prof_dsat['prof_dsat']!='0') ? $prof_dsat['prof_dsat'] : "-";?></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><? echo ($qtty_sat['qtty_sat']!='0') ? $qtty_sat['qtty_sat'] : "-";?></td>
<td><? echo round(($qtty_sat['qtty_sat']/$tot_feedback['feedback'])*100); ?></td>
<td><? echo ($qtty_dsat['qtty_dsat']!='0') ? $qtty_dsat['qtty_dsat'] : "-";?></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><? echo ($overall_sat['overall_sat']!='0') ? $overall_sat['overall_sat'] : "-";?></td>
<td><? echo round(($overall_sat['overall_sat']/$tot_feedback['feedback'])*100); ?></td>
<td><? echo ($overall_dsat['overall_dsat']!='0') ? $overall_dsat['overall_dsat'] : "-";?></td>
<td><? echo round(($overall_dsat['overall_dsat']/$tot_feedback['feedback'])*100); ?></td>
</tr>
<?php
}