header('Content-Type: text/html; charset=tis-620');
echo "";
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)");
$sql="SELECT *,sum(g) AS go,sum(s) AS sv,sum(b) AS bn
FROM tmpkap3,$_reg where kd_school != ' ' and kd_sch=scode
GROUP BY kd_school ORDER BY go desc,sv desc,bn desc limit 0,10";
$result=mysql_query($sql);
echo "
";
$row=1; $tg=0; $ts=0; $tb=0; $ta=0;
while ($db=mysql_fetch_array($result)) {
$total=$db[go]+$db[sv]+$db[bn];
$sql2="select * from $_reg where scode='$db[kd_sch]' ";
$result2=mysql_query($sql2);
$db2=mysql_fetch_array($result2);
$reg=$db2[abb_sch];
$scd=$db[kd_school];
$sql3="SELECT kd_sch,count(kd_rank) as rk1
FROM $_data WHERE kd_school='$scd' and kd_rank=1
GROUP BY kd_school";
$result3=mysql_query($sql3);
$db3=mysql_fetch_array($result3);
$rnk1=$db3[rk1];
$sql3="SELECT kd_sch,count(kd_rank) as rk2
FROM $_data WHERE kd_school='$scd' and kd_rank=2
GROUP BY kd_school";
$result3=mysql_query($sql3);
$db3=mysql_fetch_array($result3);
$rnk2=$db3[rk2];
$sql3="SELECT kd_sch,count(kd_rank) as rk3
FROM $_data WHERE kd_school='$scd' and kd_rank=3
GROUP BY kd_school";
$result3=mysql_query($sql3);
$db3=mysql_fetch_array($result3);
$rnk3=$db3[rk3];
if ($rnk1+$rnk2+$rnk3>0) {
$trp=$rnk1+$rnk2+$rnk3;
} else {
$trp='-';
}
echo "