header('Content-Type: text/html; charset=tis-620');
echo "";
include('db_config.php');
mysql_query("TRUNCATE TABLE tmpkap2");
mysql_query("insert into tmpkap2 (SELECT * FROM $_data where g+s+b>0
group by kd_sch,kd_code,g,s,b)");
$sql="select kd_code, kd_sch,sname,scode,abb_sch,sum(g) as go,sum(s) as sv,sum(b) as bn
from tmpkap2,$_sch where kd_sch=scode
group by scode order by go DESC,sv DESC,bn DESC";
$result=mysql_query($sql);
echo "
ผล$_title";
echo "
";
echo "
ที่
โรงเรียน
รวม
ตัวแทน
นักเรียน
ผู้ฝึกสอน
รวม
CEO
";
$row=1;
while ($db=mysql_fetch_array($result)) {
$total=$db[go]+$db[sv]+$db[bn];
$sql2="select kd_remark,kd_code,kd_sch,count(kd_std) as st,count(kd_tutor) as tc from $_data
where kd_sch='$db[scode]' and kd_remark='1' group by kd_code,kd_sch";
$result2=mysql_query($sql2);
$rep=mysql_num_rows($result2);
$sql3="select kd_remark,kd_code,kd_sch,count(kd_std) as st,count(kd_tutor) as tc from $_data
where kd_sch='$db[scode]' and kd_remark='1' and kd_std <> '' and kd_tutor<>'' ";
$result3=mysql_query($sql3);
$db3=mysql_fetch_array($result3);
if ($db[go]>0) { $gg=$db[go]; } else { $gg='-'; }
if ($db[sv]>0) { $ss=$db[sv]; } else { $ss='-'; }
if ($db[bn]>0) { $bb=$db[bn]; } else { $bb='-'; }
if ($rep>0) { $rr="$rep"; } else { $rr='-'; }
if ($total>0) { $tot=$total; } else { $tot='-'; }
$trr=$db3[st]+$db3[tc];
echo "