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
and kd_code not like '13%' 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 limit 0,10";
$result=mysql_query($sql);
echo "
ผล$_title";
echo "
";
echo "
ที่
โรงเรียน
1
2
3
รวมตัวแทน
CEO
";
$row=1;
while ($db=mysql_fetch_array($result)) {
$total=$db[go]+$db[sv]+$db[bn];
$sql2="select kd_remark,kd_code,kd_sch 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);
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='-'; }
echo "