<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ทดสอบ</title>
<meta charset="utf-8" />
<style type="text/css">
td{ text-align:center;}
</style>
</head>
<body>
<?php
$link = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("db_test",$link) or die(mysql_error());
mysql_query("set names utf8");
$SQL_PN = "SELECT province,pn FROM store WHERE province=10 GROUP BY pn";
$Query_PN = mysql_query($SQL_PN) or die(mysql_error());
?>
<table border="1" width="670">
<thead>
<tr>
<th>province</th>
<th>pn</th>
<th>status1</th>
<th>status2</th>
<th>status3</th>
<th>status4</th>
<th>status5</th>
</tr>
</thead>
<tbody>
<?php
while($RS_PN=mysql_fetch_array($Query_PN)){
$pv = $RS_PN[province];
$pno = $RS_PN[pn];
$sql1 = "SELECT COUNT(pn) AS st1 FROM store WHERE pn='$pno' AND status='1' ";
$sql2 = "SELECT COUNT(pn) AS st2 FROM store WHERE pn='$pno' AND status='2' ";
$sql3 = "SELECT COUNT(pn) AS st3 FROM store WHERE pn='$pno' AND status='3' ";
$sql4 = "SELECT COUNT(pn) AS st4 FROM store WHERE pn='$pno' AND status='4' ";
$sql5 = "SELECT COUNT(pn) AS st5 FROM store WHERE pn='$pno' AND status='5' ";
$Query_sql1 = mysql_query($sql1) or die(mysql_error());
$Query_sql2 = mysql_query($sql2) or die(mysql_error());
$Query_sql3 = mysql_query($sql3) or die(mysql_error());
$Query_sql4 = mysql_query($sql4) or die(mysql_error());
$Query_sql5 = mysql_query($sql5) or die(mysql_error());
while($RS_sql1=mysql_fetch_array($Query_sql1)){
while($RS_sql2=mysql_fetch_array($Query_sql2)){
while($RS_sql3=mysql_fetch_array($Query_sql3)){
while($RS_sql4=mysql_fetch_array($Query_sql4)){
while($RS_sql5=mysql_fetch_array($Query_sql5)){
?>
<tr>
<td><?=$pv;?></td>
<td><?=$pno;?></td>
<td><?=$RS_sql1[st1];?></td>
<td><?=$RS_sql2[st2];?></td>
<td><?=$RS_sql3[st3];?></td>
<td><?=$RS_sql4[st4];?></td>
<td><?=$RS_sql5[st5];?></td>
</tr>
<?php
}
}
}
}
}
}
?>
</tbody>
</table>
</body>
</html>