header('Content-Type: text/html; charset=tis-620');
include('db_config.php');
mysql_query("TRUNCATE TABLE tmpao3");
mysql_query("insert into tmpao3 (SELECT * FROM $_data
group by kd_sch,kd_code,g,s,b,kd_sp)");
$sql="SELECT kd_code, kd_sch,sname,sgrp,scode,sum(g) AS go,sum(s) AS sv,sum(b) AS bn
FROM tmpao3,$_sch WHERE kd_sch=scode GROUP BY scode ORDER BY sgrp,go DESC,sv DESC,bn DESC";
$result=mysql_query($sql);
echo "
สรุปเหรียญ $_title
ลำดับ |
โรงเรียน |
ประเภท |
|
|
|
รวม |
ชนะเลิศ |
ตัวแทน อบจ. |
";
$row=1; $tg=$ts=$tb=$tfs=$trep=0; $ag='';
while ($db=mysql_fetch_array($result)) {
$total=$db[go]+$db[sv]+$db[bn];
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]; }
$sql2="select kd_sp,kd_code,kd_sch from $_data
where kd_sch='$db[scode]' and kd_rank='1' group by kd_code,kd_sch";
$result2=mysql_query($sql2);
$fr=mysql_num_rows($result2);
$sql3="select kd_sp,kd_code,kd_sch from $_data,$_act
where kd_code=kp_code and kd_sch='$db[scode]' and kd_rank='1' and eef_rp='1'
group by kd_code";
$result3=mysql_query($sql3);
$rep=mysql_num_rows($result3);
if ($fr>0) { $frr="$fr"; $tfs+=$fr; } else { $frr='-'; }
if ($rep>0) { $rr="$rep รายการ"; $trep+=$rep; } else { $rr='-'; }
if ($db[sgrp]=='ก่อน/ประถม') {
if ($sg!==$db[sgrp]) {
$row=1;
}
$cl='#fff7d2';
} elseif ($db[sgrp]=='ขยายโอกาส') {
if ($sg!=$db[sgrp]) {
$row=1;
}
$cl='#ffeea8';
} else {
if ($sg!=$db[sgrp]) {
$row=1;
}
$cl='#ffe377';
}
echo "
$row |
$db[sname] |
$db[sgrp] |
$gg |
$ss |
$bb |
$total |
$frr |
$rr |
";
$row++ ; $tg+=$db[go]; $ts+=$db[sv]; $tb+=$db[bn]; $sg=$db[sgrp];
}
$tt=$tg+$ts+$tb ;
echo "
รวม |
$tg |
$ts |
$tb |
$tt |
$tfs |
$trep รายการ |
";
?>