header('Content-Type: text/html; charset=tis-620');
echo "";
include('db_config.php');
mysql_query("TRUNCATE TABLE tmp5sk161");
mysql_query("insert into tmp5sk161 (select * from $_data group by kd_sch,kd_code,g,s,b)");
$sql="SELECT *,sum(g) AS go,sum(s) AS sv,sum(b) AS bn
FROM tmp5sk161,$_sch,$_act WHERE kd_sch=scode and kd_code=kp_id and
level='s' and kp_cd not in ('16','17','18','19')
GROUP BY scode ORDER BY go DESC,sv DESC,bn DESC limit 0,10";
$result=mysql_query($sql);
echo "
สรุป นร.ปกติ รร.ขนาดเล็ก (< 120 คน)
ที่
โรงเรียน
ทอง
ตัวแทน
";
$row=1;
while ($db=mysql_fetch_array($result)) {
$scname=substr($db[sname],0,24);
$sql2="select * from $_data,$_act WHERE kd_code=kp_id and
kp_cd not in ('16','17','18','19') and 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 ($rep>0) { $rr="$rep"; } else { $rr='-'; }
echo "