"; include('db_config.php'); mysql_query("TRUNCATE TABLE tmp3sk161"); mysql_query("insert into tmp3sk161 (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 tmp3sk161,$_sch,$_act WHERE kd_sch=scode and kd_code=kp_id and level='s' and kp_cd not in ('16','17','18','19') GROUP BY scode ORDER BY go DESC,sv DESC,bn DESC "; $result=mysql_query($sql); echo <<สรุปเหรียญนักเรียนปกติ รร.ขนาดเล็ก $_title TH; $row=1; $tg=0; $ts=0; $tb=0; $tt=0; $trp1=0; $trp2=0; while ($db=mysql_fetch_array($result)) { $total=$db[go]+$db[sv]+$db[bn]; $sql1="select * from $_data,$_act WHERE kd_code=kp_id and kp_cd not in ('16','17','18','19') and kd_sch='$db[scode]' and kd_remark='1' group by kd_code,kd_sch"; $result1=mysql_query($sql1); $rep1=mysql_num_rows($result1); $sql2="select * from ssk161_data where kd_sch='$db[scode]' and kd_code not like 'sp%' group by kd_code,kd_sch"; $result2=mysql_query($sql2); $rep2=mysql_num_rows($result2); 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 ($rep1>0) { $rr1="$rep1"; } else { $rr1='-'; } if ($total>0) { $tot=$total; } else { $tot='-'; } echo << TB; $row++ ; $tg+=$db[go]; $ts+=$db[sv]; $tb+=$db[bn]; $ta+=$db[ad]; $tt+=$total; $trp1+=$rep1; $ta2+=$db[ad]; } echo <<
ที่ โรงเรียน ชมเชย รวม ตัวแทน กลุ่ม
$row $db[sname] $gg $ss $bb $aa $tot $rr1 $db[abb_sch]
รวมนักเรียนปกติ $tg $ts $tb $ta $tt $trp1  
TF; ?>