header('Content-Type: text/html; charset=tis-620');
include('db_config.php');
mysql_query("TRUNCATE TABLE tmpao1");
mysql_query("insert into tmpao1 (SELECT * FROM $_reg group by kd_sch,kd_code,g,s,b,kd_sp)");
$sql="SELECT *,sum(g) AS go,sum(s) AS sv,sum(b) AS bn
FROM tmpao1,$_sch WHERE kd_sch=scode GROUP BY scode ORDER BY sgrp,go DESC,sv DESC,bn DESC";
$result=mysql_query($sql);
echo "
สรุปเหรียญ $_titlereg
ลำดับ |
โรงเรียน |
ประเภท |
ตัวแทน อบจ. |
|
|
|
รวม |
ชนะ เลิศ |
ที่ 2 |
ที่ 3 |
ตัวแทน ภาคฯ |
เข้าระบบ |
";
$row=1; $tg=0; $ts=0; $tb=0; $ag='';
while ($db=mysql_fetch_array($result)) {
$total=$db[go]+$db[sv]+$db[bn];
if ($total==0) { $tt='-'; } else { $tt=$total; }
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 $_reg
where kd_sch='$db[scode]' and kd_rank='1' group by kd_code,kd_sch";
$result2=mysql_query($sql2);
$fr=mysql_num_rows($result2);
$sql2="select kd_sp,kd_code,kd_sch from $_reg
where kd_sch='$db[scode]' and kd_rank='2' group by kd_code,kd_sch";
$result2=mysql_query($sql2);
$nd=mysql_num_rows($result2);
$sql2="select kd_sp,kd_code,kd_sch from $_reg
where kd_sch='$db[scode]' and kd_rank='3' group by kd_code,kd_sch";
$result2=mysql_query($sql2);
$rd=mysql_num_rows($result2);
$sql3="select * from $_reg where kd_remark=1 and kd_sch='$db[scode]'
group by kd_code";
$result3=mysql_query($sql3);
$rep0=mysql_num_rows($result3);
$sql4="select * from $_reg where kd_rank in (1,2,3) and kd_sch='$db[scode]'
group by kd_code";
$result4=mysql_query($sql4);
$regrp=mysql_num_rows($result4);
if ($fr>0) { $frr="$fr"; } else { $frr='-'; }
if ($nd>0) { $fnd="$nd"; } else { $fnd='-'; }
if ($rd>0) { $frd="$rd"; } else { $frd='-'; }
if ($rep0>0) { $rr0="$rep0"; } else { $rr0='-'; }
if ($regrp>0) { $rr="$regrp"; } else { $rr='-'; }
if ($db[sgrp]=='ก่อน/ประถม') {
if ($sg!==$db[sgrp]) {
$row=1;
}
$cl='#ddeeff';
} elseif ($db[sgrp]=='ขยายโอกาส') {
if ($sg!=$db[sgrp]) {
$row=1;
}
$cl='#cce6ff';
} else {
if ($sg!=$db[sgrp]) {
$row=1;
}
$cl='#b7dbff';
}
echo "
$row |
$db[sname] |
$db[sgrp] |
$rr0 |
$gg |
$ss |
$bb |
$tt |
$frr |
$fnd |
$frd |
$rr |
รายงานผล |
";
$row++; $trep+=$rep0; $tg+=$db[go]; $ts+=$db[sv]; $tb+=$db[bn]; $sg=$db[sgrp];
$sst+=$fr; $snd+=$nd; $srd+=$rd;
}
$ttm=$tg+$ts+$tb; $tss=$sst+$snd+$srd;
echo "
รวม |
$trep |
$tg |
$ts |
$tb |
$ttm |
$sst |
$snd |
$srd |
$tss |
|
";
?>