header('Content-Type: text/html; charset=tis-620');
echo "";
include('db_config.php');
mysql_query("TRUNCATE TABLE tmp6sk161");
mysql_query("insert into tmp6sk161 (SELECT * FROM ssk161_data where kd_code not like 'sp%'
group by kd_sch,kd_code,g,s,b)");
$sql="SELECT kd_code,kd_sch,sname,scode,level,abb_sch,sum(g) AS go,sum(s) AS sv,sum(b) AS bn
FROM tmp6sk161,ceo61_sch WHERE kd_sch=scode and level='o'
GROUP BY scode ORDER BY go DESC,sv DESC,bn DESC limit 0,10";
$result=mysql_query($sql);
echo "
สรุป รร.ประถมขยายโอกาส ป.1-ม.3 ";
echo "
";
echo "
ที่
โรงเรียน
รวม
ตัวแทน
";
$row=1;
while ($db=mysql_fetch_array($result)) {
$total=$db[go]+$db[sv]+$db[bn];
$scname=substr($db[sname],0,16);
$sql2="select kd_remark,kd_code,kd_sch from ssk161_data
where kd_sch='$db[scode]' and (kd_remark='1' or kd_sp='1')
and kd_code not like 'sp%' 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 "