header('Content-Type: text/html; charset=tis-620');
echo "";
include('db_config.php');
mysql_query("TRUNCATE TABLE tmpkap4");
mysql_query("insert into tmpkap4 (SELECT * FROM $_data
where g+s+b+a > 0 group by kd_sch,kd_code,g,s,b,a,kd_sp)");
$sql="SELECT *,sum(g) AS go,sum(s) AS sv,sum(b) AS bn,sum(a) AS ad
FROM tmpkap4,$_reg where kd_school != '0' and kd_sch=scode
GROUP BY kd_school ORDER BY go desc,sv desc,bn desc";
$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]+$db[ad];
// $sql2="select * from $_reg where scode='$db[kd_sch]' ";
// $result2=mysql_query($sql2);
// $db2=mysql_fetch_array($result2);
$reg=$db[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='-';
}
if ($db[go]==0) { $gg='-'; } else { $gg=$db[go]; }
if ($db[sv]==0) { $ss='-'; } else { $ss=$db[sv]; }
if ($db[bn]==0) { $bb='-'; } else { $bb=$db[bn]; }
if ($db[ad]==0) { $aa='-'; } else { $aa=$db[ad]; }
echo "