"; include('db_config.php'); mysql_query("TRUNCATE TABLE tmpkap3"); mysql_query("insert into tmpkap3 (SELECT * FROM $_data group by kd_sch,kd_code,g,s,b,a)"); $sql="select *,sum(kd_remark) as nrep,sum(g) as go,sum(s) as sv,sum(b) as bn,sum(a) as ad, count(kd_code) as sendall from tmpkap3,$_sch where kd_sch=scode and scgrp='$ceo' group by kd_sch order by nrep desc "; $result=mysql_query($sql); $rk=1; echo <<สรุป $_title แยก CEO เรียงตามจำนวนตัวแทน TH; $tg=0; $ts=0; $tb=0; $total=0; $rk=1; $tsend=0; while ($db=mysql_fetch_array($result)) { $tot=$db[go]+$db[sv]+$db[bn]+$db[ad]; $scn=substr($db[sname],0,50); $sgr=$db[abb_sch]; $sper=number_format($tot*100/$db[sendall],2,'.',','); if($db[go]>0) { $go=$db[go]; } else { $go='-'; } if($db[sv]>0) { $sv=$db[sv]; } else { $sv='-'; } if($db[bn]>0) { $bn=$db[bn]; } else { $bn='-'; } if($db[ad]>0) { $ad=$db[ad]; } else { $ad='-'; } if($db[nrep]>0) { $rp=$db[nrep]; } else { $rp='-'; } echo << TB; $rk++; $tg+=$db[go]; $ts+=$db[sv]; $tb+=$db[bn]; $ta+=$db[ad]; $total+=$tot; $tsend+=$db[sendall]; $trep+=$db[nrep]; } $tsper=number_format($total*100/$tsend,2,'.',','); echo <<
ที่ โรงเรียน สมัครรวม ทอง เงิน ทองแดง ชมเชย รวม ร้อยละ ตัวแทน
$rk $scn $db[sendall] $go $sv $bn $ad $tot $sper $rp
รวม CEO $sgr $tsend $tg $ts $tb $ta $total $tsper $trep
TF; ?>