"; include('db_config.php'); mysql_query("TRUNCATE TABLE tmpkap2"); mysql_query("insert into tmpkap2 (SELECT * FROM $_data group by kd_sch,kd_code,g,s,b,a)"); $sql="select kd_code, kd_sch,sname,scode,abb_sch,sum(g) as go,sum(s) as sv,sum(b) as bn,sum(a) as ad from tmpkap2,$_sch where kd_sch=scode group by scode order by go DESC,sv DESC,bn DESC,ad DESC"; $result=mysql_query($sql); echo "
สรุปผลเหรียญรางวัล $_title "; $row=1; $tg=$ts=$tb=$ta=$tst=0; while ($db=mysql_fetch_array($result)) { if ($row%2) { $cl='#f5f5f5'; } else { $cl='#e1e1e1'; } $total=$db[go]+$db[sv]+$db[bn]+$db[ad]; $sql2="select kd_remark,kd_code,kd_sch,count(kd_std) as st,count(kd_tutor) as tc from $_data where kd_sch='$db[scode]' and kd_remark='1' group by kd_code,kd_sch"; $result2=mysql_query($sql2); $rep=mysql_num_rows($result2); $sql3="select kd_remark,kd_code,kd_sch,count(kd_std) as st from $_data where kd_sch='$db[scode]' and kd_remark='1' and kd_std <>'' "; $result3=mysql_query($sql3); $db3=mysql_fetch_array($result3); 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 ($db[ad]>0) { $aa=$db[ad]; } else { $aa='-'; } if ($rep>0) { $rr="$rep"; } else { $rr='-'; } if ($db3[st]>0) { $std="$db3[st]"; } else { $std='-'; } if ($total>0) { $tot=$total; } else { $tot='-'; } echo ""; $row++ ; $rtotal+=$rr; $tg+=$db[go]; $ts+=$db[sv]; $tb+=$db[bn]; $ta+=$db[ad]; $tst+=$std; } $ttg=number_format($tg,0,'.',','); $tts=number_format($ts,0,'.',','); $ttb=number_format($tb,0,'.',','); $tta=number_format($ta,0,'.',','); $ttt=number_format($tg+$tb+$tb+$ta,0,'.',','); $ttst=number_format($tst,0,'.',','); echo "
ที่ โรงเรียน ทอง เงิน ทองแดง ชมเชย รวม ตัวแทน นักเรียน CEO
$row $db[sname] $gg $ss $bb $aa $tot $rr $std $db[abb_sch]
$ttg $tts $ttb $tta $ttt $rtotal $ttst  
[ อับเดทล่าสุด ]
"; ?>