count จำนวนแสดงในตารางยังงัยดีให้ไว ลองทำแบบนี้ได้แต่กลัวว่าถ้าครบทุกห้องจะช้ามากนะครับ
Code (PHP)
echo $resultall['num_11b'];
Date :
2012-11-14 07:49:46
By :
comscience_009
Code (PHP)
$queryall = $db->query("SELECT COUNT(*) AS num_11b, tb_student_tname FROM tb_students WHERE tb_student_degree='ม.1/1' GROUP BY tb_student_tname");
while($resultall = $db->fetch_array($queryall)){
echo $resultall['num_11b'];
}
ต้องทำแบบนี้ หกสิบห้องใช่ไหม ครับ
Date :
2012-11-14 12:29:27
By :
deknoy
ลองดูน่ะครับ น่าจะไก้ไอเดียอะไรไปบ้างล่ะครับ
$rooms = array("ม.1/1","ม.2/1","ม.3/1","ม.4/1","ม.5/1","ม.6/1","ม.1/2","ม.2/2","ม.3/2","ม.4/2","ม.5/2","ม.6/2");
$i=1;
foreach($rooms as $eachroom){
$sql = "SELECT COUNT(*) AS num, tb_student_tname , tb_student_degree FROM tb_students WHERE tb_student_degree='$eachroom' GROUP BY tb_student_tname";
$result = $db->query($sql);
while($data = $db->fetch_array($result)){
echo $data["tb_student_degree"]." / ".$data[" tb_student_tname"]." / ".$data["num"]." ";
if($i%6 == 0) echo "<br />";
$i++;
}
}
Date :
2012-11-14 22:29:48
By :
sakuraei
แถว 1 2 มันไม่ลงช่องอะครับ ผมทำไรผิดหว่า งง
Code (PHP)
<?php
$rooms = array("ม.1/1","ม.2/1","ม.3/1","ม.4/1","ม.5/1","ม.6/1","ม.1/2","ม.2/2" ,"ม.3/2","ม.4/2","ม.5/2","ม.6/2","ม.1/3","ม.2/3","ม.3/3","ม.4/3","ม.5/3" ,"ม.6/3","ม.1/4","ม.2/4","ม.3/4","ม.4/4","ม.5/4","ม.6/4","ม.1/5","ม.2/5", "ม.3/5","ม.4/5","ม.5/5","ม.6/5","ม.1/6","ม.2/6","ม.3/6","ม.4/6","ม.5/6" ,"ม.6/6","ม.1/7","ม.2/7","ม.3/7","ม.4/7","ม.5/7","ม.6/7","ม.1/8","ม.2/8" ,"ม.3/8","ม.4/8","ม.5/8","ม.6/8","ม.1/9","ม.2/9","ม.3/9","ม.4/9","ม.5/9", "ม.6/9","ม.1/10","ม.2/10","ม.3/10","ม.4/10","ม.5/10","ม.6/10","ม.1/11" ,"ม.2/11","ม.3/11","ม.4/11","ม.5/11","ม.6/11","ม.1/12","ม.2/12","ม.3/12","ม.4/12","ม.5/12","ม.6/12");
$i=1;
foreach($rooms as $eachroom){
$sql = "SELECT COUNT(*) AS num, tb_student_tname , tb_student_degree FROM tb_students WHERE tb_student_degree='$eachroom' GROUP BY tb_student_tname";
$result = $db->query($sql);
while($data = $db->fetch_array($result)){
// echo $data["tb_student_degree"]." ".$data["tb_student_tname"]." ".$data["num"]." คน<br>";
// if($i%12 == 0) echo "<br />";
?>
<tr height="31">
<td height="31" align="center" bgcolor="#99FF66"><?php echo $i;?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
<td align="center" bgcolor="#99FF66"><?php echo $data["num"];?></td>
</tr>
<?php
$i++;
}
}
?>
Date :
2012-11-18 12:43:45
By :
comscience_009
ทดลองแล้วจับภาพหน้าจอมาให้ดูด้วยน่ะครับ
<?php
$rooms = array("ม.1/1","ม.2/1","ม.3/1","ม.4/1","ม.5/1","ม.6/1","ม.1/2" ,"ม.2/2","ม.3/2","ม.4/2","ม.5/2","ม.6/2","ม.1/3","ม.2/3","ม.3/3" ,"ม.4/3","ม.5/3","ม.6/3","ม.1/4","ม.2/4","ม.3/4","ม.4/4","ม.5/4" ,"ม.6/4" ,"ม.1/5","ม.2/5","ม.3/5","ม.4/5","ม.5/5","ม.6/5","ม.1/6", "ม.2/6","ม.3/6","ม.4/6","ม.5/6","ม.6/6","ม.1/7","ม.2/7","ม.3/7","ม.4/7" ,"ม.5/7","ม.6/7","ม.1/8","ม.2/8","ม.3/8","ม.4/8","ม.5/8","ม.6/8","ม.1/9" ,"ม.2/9","ม.3/9","ม.4/9","ม.5/9","ม.6/9","ม.1/10","ม.2/10","ม.3/10" ,"ม.4/10","ม.5/10","ม.6/10","ม.1/11","ม.2/11","ม.3/11","ม.4/11","ม.5/11","ม.6/11","ม.1/12","ม.2/12","ม.3/12","ม.4/12","ม.5/12","ม.6/12");
$i=1;
$class=1;
foreach($rooms as $eachroom){
$sql = "SELECT COUNT(*) AS num, tb_student_tname , tb_student_degree FROM tb_students WHERE tb_student_degree='$eachroom' GROUP BY tb_student_tname";
$result = $db->query($sql);
while($data[] = $db->fetch_array($result)){;}
// echo $data["tb_student_degree"]." ".$data["tb_student_tname"]." ".$data["num"]." คน<br>";
// if($i%12 == 0) echo "<br />";
if($class == 1){
echo "<tr height=\"31\">\n";
echo "<td height=\"31\" align=\"center\" bgcolor=\"#99FF66\">$i</td>";
}
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data[0]["num"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data[1]["num"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\"> </td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\"> </td>";
if($class == 6){
echo "</tr>\n"; $class=1;
}else{
$class++;
}
unset($data);
$i++;
}
?>
Date :
2012-11-18 13:04:14
By :
sakuraei
เกือบๆ ล่ะครับ ลองใหม่น่ะ
<?php
$rooms = array("ม.1/1","ม.2/1","ม.3/1","ม.4/1","ม.5/1","ม.6/1","ม.1/2","ม.2/2" ,"ม.3/2","ม.4/2","ม.5/2","ม.6/2","ม.1/3","ม.2/3","ม.3/3","ม.4/3","ม.5/3" ,"ม.6/3","ม.1/4","ม.2/4","ม.3/4","ม.4/4","ม.5/4","ม.6/4","ม.1/5","ม.2/5" ,"ม.3/5","ม.4/5","ม.5/5","ม.6/5","ม.1/6","ม.2/6","ม.3/6","ม.4/6","ม.5/6" ,"ม.6/6","ม.1/7","ม.2/7","ม.3/7","ม.4/7","ม.5/7","ม.6/7","ม.1/8","ม.2/8" ,"ม.3/8","ม.4/8","ม.5/8","ม.6/8","ม.1/9","ม.2/9","ม.3/9","ม.4/9","ม.5/9" ,"ม.6/9","ม.1/10","ม.2/10","ม.3/10","ม.4/10","ม.5/10","ม.6/10","ม.1/11" ,"ม.2/11","ม.3/11","ม.4/11","ม.5/11","ม.6/11","ม.1/12","ม.2/12","ม.3/12","ม.4/12","ม.5/12","ม.6/12");
$i=1;
$class=1;
foreach($rooms as $eachroom){
$sql = "SELECT COUNT(*) AS num, tb_student_tname , tb_student_degree FROM tb_students WHERE tb_student_degree='$eachroom' GROUP BY tb_student_tname";
$result = $db->query($sql);
while($data[] = $db->fetch_array($result)){;}
// echo $data["tb_student_degree"]." ".$data["tb_student_tname"]." ".$data["num"]." คน<br>";
// if($i%12 == 0) echo "<br />";
if($class == 1){
echo "<tr height=\"31\">\n";
echo "<td height=\"31\" align=\"center\" bgcolor=\"#99FF66\">$i</td>";
}
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data[0]["num"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data[1]["num"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\"> </td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\"> </td>";
if($class == 6){
echo "</tr>\n"; $class=1; $i++;
}else{
$class++;
}
unset($data);
}
?>
Date :
2012-11-18 14:15:56
By :
sakuraei
หลักการเดียวกัน ตั้งชื่อตัวแปรที่จะรับข้อมูลจากตารางอื่นเป็น $data2 แล้วกันครับ
ขอแค่ [ ส่งคำขอบคุณ ] ก็พอ
Date :
2012-11-18 14:30:06
By :
sakuraei
Code (PHP)
<?php
$rooms = array("ม.1/1","ม.2/1","ม.3/1","ม.4/1","ม.5/1","ม.6/1","ม.1/2" ,"ม.2/2","ม.3/2","ม.4/2","ม.5/2","ม.6/2","ม.1/3","ม.2/3","ม.3/3" ,"ม.4/3","ม.5/3","ม.6/3","ม.1/4","ม.2/4","ม.3/4","ม.4/4","ม.5/4" ,"ม.6/4","ม.1/5","ม.2/5","ม.3/5","ม.4/5","ม.5/5","ม.6/5","ม.1/6" ,"ม.2/6","ม.3/6","ม.4/6","ม.5/6","ม.6/6","ม.1/7","ม.2/7","ม.3/7" ,"ม.4/7","ม.5/7","ม.6/7","ม.1/8","ม.2/8","ม.3/8","ม.4/8","ม.5/8" ,"ม.6/8","ม.1/9","ม.2/9","ม.3/9","ม.4/9","ม.5/9","ม.6/9","ม.1/10", "ม.2/10","ม.3/10","ม.4/10","ม.5/10","ม.6/10","ม.1/11","ม.2/11" ,"ม.3/11","ม.4/11","ม.5/11","ม.6/11","ม.1/12","ม.2/12","ม.3/12","ม.4/12","ม.5/12","ม.6/12");
$i=1;
$class=1;
foreach($rooms as $eachroom){
$sql = "SELECT COUNT(*) AS num, tb_student_tname , tb_student_degree FROM tb_students WHERE tb_student_degree='$eachroom' GROUP BY tb_student_tname";
$result = $db->query($sql);
while($data[] = $db->fetch_array($result)){
}
$sql2 = "SELECT COUNT(*) AS numlate, tb_time_tname , tb_time_degree FROM tb_times WHERE tb_time_degree='$eachroom' AND tb_time_type !='1' GROUP BY tb_time_tname";
$result2 = $db->query($sql2);
while($data2[] = $db->fetch_array($result2)){
}
if($class == 1){
echo "<tr height=\"31\">\n";
echo "<td height=\"31\" align=\"center\" bgcolor=\"#99FF66\">$i</td>";
}
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data[0]["num"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data[1]["num"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data2[0]["numlate"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data2[1]["numlate"]}</td>";
if($class == 6){
echo "</tr>\n"; $class=1; $i++;
}else{
$class++;
}
unset($data);
}
?>
ผมลองเพิ่ม query อีกตัวเพื่อดึงนักเรียนขาดเรียนเข้ามาแสดง แต่ทำไม่มันได้ค่าว่างทั้งที่เอาไปลอง query แยก กลับได้ค่าอะครับ
พลาดตรงไหนอะ แล้วถ้าจะ sum แสดงถ้าล่างต้องทำไงอะ ครับ ใกล้สำเร็จละครับ ขอบคุณล่วงหน้า
Date :
2012-11-18 17:05:07
By :
comscience_009
unset($data); unset($data2);
Date :
2012-11-18 19:22:45
By :
unidentifier
ลองดูน่ะครับ ผมไม่ได้ทดสอบเลย แต่คิดว่าน่าจะผ่าน
<?php
$rooms = array("ม.1/1","ม.2/1","ม.3/1","ม.4/1","ม.5/1","ม.6/1","ม.1/2" ,"ม.2/2","ม.3/2","ม.4/2","ม.5/2","ม.6/2","ม.1/3","ม.2/3","ม.3/3" ,"ม.4/3","ม.5/3","ม.6/3","ม.1/4","ม.2/4","ม.3/4","ม.4/4","ม.5/4" ,"ม.6/4","ม.1/5","ม.2/5","ม.3/5","ม.4/5","ม.5/5","ม.6/5","ม.1/6" ,"ม.2/6","ม.3/6","ม.4/6","ม.5/6","ม.6/6","ม.1/7","ม.2/7","ม.3/7" ,"ม.4/7","ม.5/7","ม.6/7","ม.1/8","ม.2/8","ม.3/8","ม.4/8","ม.5/8" ,"ม.6/8","ม.1/9","ม.2/9","ม.3/9","ม.4/9","ม.5/9","ม.6/9","ม.1/10", "ม.2/10","ม.3/10","ม.4/10","ม.5/10","ม.6/10","ม.1/11","ม.2/11" ,"ม.3/11","ม.4/11","ม.5/11","ม.6/11","ม.1/12","ม.2/12","ม.3/12","ม.4/12","ม.5/12","ม.6/12");
$i=1;
$class=1;
foreach($rooms as $eachroom){
$sql = "SELECT COUNT(*) AS num, tb_student_tname , tb_student_degree FROM tb_students WHERE tb_student_degree='$eachroom' GROUP BY tb_student_tname";
$result = $db->query($sql);
while($data[] = $db->fetch_array($result)){
}
$sql2 = "SELECT COUNT(*) AS numlate, tb_time_tname , tb_time_degree FROM tb_times WHERE tb_time_degree='$eachroom' AND tb_time_type !='1' GROUP BY tb_time_tname";
$result2 = $db->query($sql2);
while($data2[] = $db->fetch_array($result2)){
}
if($class == 1){
echo "<tr height=\"31\">\n";
echo "<td height=\"31\" align=\"center\" bgcolor=\"#99FF66\">$i</td>";
}
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data[0]["num"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data[1]["num"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data2[0]["numlate"]}</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">{$data2[1]["numlate"]}</td>";
$total["m".$class] += $data[0]["num"];
$total["f".$class] += $data[1]["num"];
$total["absent_m".$class] += $data2[0]["numlate"];
$total["absent_f".$class] += $data2[1]["numlate"];
if($class == 6){
echo "</tr>\n"; $class=1; $i++;
}else{
$class++;
}
unset($data);
unset($data2);
}
echo "\n<tr><td>รวม</td><td>{$total["m1"]}</td><td>{$total["f1"]}</td><td>{$total["absent_m1"]}</td><td>{$total["absent_f1"]}</td>";
echo "<td>{$total["m2"]}</td><td>{$total["f2"]}</td><td>{$total["absent_m2"]}</td><td>{$total["absent_f2"]}</td>";
echo "<td>{$total["m3"]}</td><td>{$total["f3"]}</td><td>{$total["absent_m3"]}</td><td>{$total["absent_f3"]}</td>";
echo "<td>{$total["m4"]}</td><td>{$total["f4"]}</td><td>{$total["absent_m4"]}</td><td>{$total["absent_f4"]}</td>";
echo "<td>{$total["m5"]}</td><td>{$total["f5"]}</td><td>{$total["absent_m5"]}</td><td>{$total["absent_f5"]}</td>";
echo "<td>{$total["m6"]}</td><td>{$total["f6"]}</td><td>{$total["absent_m6"]}</td><td>{$total["absent_f6"]}</td></tr>\n";
?>
ประวัติการแก้ไข 2012-11-18 22:44:43
Date :
2012-11-18 22:38:46
By :
sakuraei
ทดสอบแล้วช่วยจับภาพหน้าจอมาให้ดูด้วยน่ะครับ
Date :
2012-11-18 22:43:11
By :
sakuraei
$total["absent_m".$class] += $data2[0]["numlate"];
$total["absent_f".$class] += $data2[1]["numlate"];
ได้ละครับ ขอบคุณ
Date :
2012-11-18 22:49:42
By :
comscience_009
เรียบร้อย ครบถ้วนกระบวนความแล้วใช่ป่ะ???
ประวัติการแก้ไข 2012-11-18 22:54:37
Date :
2012-11-18 22:53:28
By :
sakuraei
{$data2[0]["numlate"]}
ถ้าจะเช็คว่าไม่มีค่าให้แสดง 0 ทำไงได้มั้งอะ ท่าน
Date :
2012-11-18 22:59:18
By :
comscience_009
echo "<td align=\"center\" bgcolor=\"#99FF66\">".(($data2[0]["numlate"]==0)?"-":$data2[0]["numlate"])."</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">".(($data2[1]["numlate"]==0)?"-":$data2[1]["numlate"])."</td>";
หรือ
echo "<td align=\"center\" bgcolor=\"#99FF66\">".( (is_null($data2[0]["numlate"]))?"-":$data2[0]["numlate"])."</td>";
echo "<td align=\"center\" bgcolor=\"#99FF66\">".( (is_null($data2[1]["numlate"))?"-":$data2[1]["numlate"])."</td>";
ประวัติการแก้ไข 2012-11-18 23:15:13
Date :
2012-11-18 23:11:11
By :
sakuraei
มีอะไรก็แวะเวียนมาถามได้ครับ ที่นี่มีเพื่อนๆที่มีจิตอาสาอยู่เยอะ
ขอแค่แวะมาให้คะแนนผมบ่อยๆ น่ะครับ อิๆๆ
ประวัติการแก้ไข 2012-11-18 23:38:02 2012-11-18 23:58:30
Date :
2012-11-18 23:36:44
By :
sakuraei
มีคำถามมาอีกแล้ว จะดึงไง ในกรณีืที่ห้องเราเก็บเป็น ID ไว้เพราะต้องเอาไว้ใช้อะครับ
select * from tb_rooms order by tb_room_id asc
แล้วเอา tb_room_id มาใช้อะครับ
Date :
2013-05-02 01:15:39
By :
cs45mcru
Code (PHP)
$rooms = array("ม.1/1","ม.2/1","ม.3/1","ม.4/1","ม.5/1","ม.6/1","ม.1/2","ม.2/2" ,"ม.3/2","ม.4/2","ม.5/2","ม.6/2","ม.1/3","ม.2/3","ม.3/3","ม.4/3","ม.5/3" ,"ม.6/3","ม.1/4","ม.2/4","ม.3/4","ม.4/4","ม.5/4","ม.6/4","ม.1/5","ม.2/5" ,"ม.3/5","ม.4/5","ม.5/5","ม.6/5","ม.1/6","ม.2/6","ม.3/6","ม.4/6","ม.5/6" ,"ม.6/6","ม.1/7","ม.2/7","ม.3/7","ม.4/7","ม.5/7","ม.6/7","ม.1/8","ม.2/8" ,"ม.3/8","ม.4/8","ม.5/8","ม.6/8","ม.1/9","ม.2/9","ม.3/9","ม.4/9","ม.5/9" ,"ม.6/9","ม.1/10","ม.2/10","ม.3/10","ม.4/10","ม.5/10","ม.6/10","ม.1/11" ,"ม.2/11","ม.3/11","ม.4/11","ม.5/11","ม.6/11","ม.1/12","ม.2/12","ม.3/12","ม.4/12","ม.5/12","ม.6/12");
คิอห้องพวกนี้เรา เก็บลง table ด้วยอะครับ
Date :
2013-05-02 01:28:43
By :
cs45mcru
Load balance : Server 02