สอบถาม เรื่อง การนับค่าที่ได้จาก echo ซึ่งเป็นข้อมูลที่ได้จากการประมวลผลเรียบร้อยแล้ว

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถาม เรื่อง การนับค่าที่ได้จาก echo ซึ่งเป็นข้อมูลที่ได้จากการประมวลผลเรียบร้อยแล้ว

สอบถาม เรื่อง การนับค่าที่ได้จาก echo ซึ่งเป็นข้อมูลที่ได้จากการประมวลผลเรียบร้อยแล้ว
สอบถามเกี่ยวกับ การนับจำนวนข้อมูลที่ผ่านการคิวรี่ จากหลายตาราง มาทำการคำนวณ และแสดงผลออกมาecho แล้ว  จะมีวิธีการนับอย่างไรค่ะ 

 

อันนี้เป็น code 
include ('config.php');								
$strSQL1=" SELECT tbp_answer.*,tb_answer.*,tbs_answer.*,tb_students.*
,tb_teacher.*,
SUM(IF(FIND_IN_SET(tbp_answer.id_question,'3,8,13,16,24')  ,tbp_answer.score_p+tb_answer.score+tbs_answer.score_s,0))  as all1,
SUM(IF(FIND_IN_SET(tbp_answer.id_question,'5,7,12,18,22')  ,tbp_answer.score_p+tb_answer.score+tbs_answer.score_s,0))  as all2,
SUM(IF(FIND_IN_SET(tbp_answer.id_question,'2,10,15,21,25')  ,tbp_answer.score_p+tb_answer.score+tbs_answer.score_s,0))  as all3,
SUM(IF(FIND_IN_SET(tbp_answer.id_question,'6,11,14,19,23')  ,tbp_answer.score_p+tb_answer.score+tbs_answer.score_s,0))  as all4,
SUM(IF(FIND_IN_SET(tbp_answer.id_question,'1,4,9,17,20')  ,tbp_answer.score_p+tb_answer.score+tbs_answer.score_s,0))  as all5
FROM tbp_answer 
LEFT JOIN tb_answer
ON  tbp_answer.id_student =tb_answer.id_student
AND tbp_answer.id_question=tb_answer.id_question 
	JOIN tbs_answer
ON  tb_answer.id_student =tbs_answer.id_student
AND tb_answer.id_question=tbs_answer.id_question
	JOIN tb_students
ON  tbs_answer.id_student =tb_students.id_student
	JOIN tb_teacher
ON  tbp_answer.id_teacher =tb_teacher.id_teacher
WHERE tb_teacher.username = '".$_SESSION['username']."' 
GROUP BY tb_students.id_student ";
$objQuery1 = mysql_query($strSQL1) or die ("Error Query [".$strSQL1."]");
	while($row = mysql_fetch_array($objQuery1)) { 
	?>
	<tr>
	
 	<td align="center"><?= $row['id_student']; ?></td>
 	<td><?= $row['Name']; ?></td>
 	
 	<td align="center">
 		<? if ($row[sex_s]=="1"){
  		echo "ชาย";  	
  		} elseif($row[sex_s]=="2"){
  		echo "หญิง"; 
  		}?>
  	</td>
 	 	
 	 	
 	 	
 	<td align="center"><?echo number_format($a1=$row['all1']/3, 2, '.', ''); ?>
 	<? if ($a1<=3){
	   echo "= ปกติ";
   }elseif($a1<=4){
   	   echo "= เสี่ยง";
   }elseif($a1>4){
   	   echo "= ปัญหา";   
   }
	?>
	</td>
	
	<td align="center"><?echo number_format($a2=$row['all2']/3, 2, '.', ''); ?>
 	<? if ($a2<=3){
	    echo "= ปกติ";
   }elseif($a2<=4){
   	   echo "= เสี่ยง";
   }elseif($a2>4){
   	   echo "= ปัญหา";   
   }
	?>	
	</td>
	
	<td align="center"><?echo number_format($a3=$row['all3']/3, 2, '.', ''); ?>
 	<? if ($a3<=5){
	   echo "= ปกติ";
   }elseif($a3<=6){
   	   echo "= เสี่ยง";
   }elseif($a3>6){
   	   echo "= ปัญหา";   
   }
	?>
	</td>
	
	<td align="center"><?echo number_format($a3=$row['all3']/3, 2, '.', ''); ?>
 	<? if ($a4<=5){
	   echo "= ปกติ";
   }elseif($a4<=6){
   	   echo "= เสี่ยง";
   }elseif($a4>6){
   	   echo "= ปัญหา";   
   }
	?>	
	</td>
	
	<td align="center"><? echo number_format( $a=$row['all1']/3+$row['all2']/3+$row['all3']/3+$row['all4']/3, 2, '.', ''); ?>
 	<? if ($a<=15){
	   echo "= ปกติ";
   }elseif($a<=17){
   	   echo "= เสี่ยง";
   }elseif($a>17){
   	   echo "= ปัญหา";   
   }
	?>	
	</td>
	
	<td align="center"><?echo number_format($a5=$row['all5']/3, 2, '.', ''); ?>
 	<? if ($a5<=3){
	   echo "= ไม่มีจุดแข็ง";
   }elseif($a5>4){
   	   echo "= เป็นจุดแข็ง";   
   }
	?>	
	</td>
	</tr>
<?}?>
</table>





Tata.com 1.46.65.xxx 28-04-2017 20:19:12

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
ลองสร้างเป็น array 3 มิติเข้าไปเก็บค่า แล้วค่อยใช้คำสั่ง count() นับจำนวน
เช่น 

$arr_case['normal'][ด้านที่][ไอดีนักเรียน]=1;

 
สมมติในส่วนด้านที่ 1
 
    <? if ($a1<=3){
       echo "= ปกติ";
   }elseif($a1<=4){
       echo "= เสี่ยง";
   }elseif($a1>4){
       echo "= ปัญหา";   
   }
    ?>    
    
    ก็ใส่เป็น
 
    <? if ($a1<=3){
		$arr_case['normal'][1][$row['id_student']]=1;
       echo "= ปกติ";
   }elseif($a1<=4){
	   $arr_case['risk'][1][$row['id_student']]=1;
       echo "= เสี่ยง";
   }elseif($a1>4){
	   $arr_case['trouble'][1][$row['id_student']]=1;
       echo "= ปัญหา";   
   }
    ?>  
 
แทรกคล้ายๆ แบบนี้ ในอีก 4 ด้านที่เหลือ เปลี่ยนเฉพาะมิติที่สองตรง [ด้านที่] เป็นเลขกำกับด้าน เช่น 2, 3 , .....
 
เวลาเรียกใช้ก็ใช้คำสั่ง ประมาณนี้ สำหรับด้านที่ 1
 
<?=(isset($arr_case['normal'][1]))?count($arr_case['normal'][1]):0?>
<?=(isset($arr_case['risk'][1]))?count($arr_case['risk'][1]):0?>
<?=(isset($arr_case['trouble'][1]))?count($arr_case['trouble'][1]):0?>
 
แทรกแบบนี้ให้ครบอีกสี่ด้านที่เหลือ เปลี่ยนเฉพาะมิติที่สองตรง [ด้านที่] เป็นเลขกำกับด้าน เช่น 2, 3 , .....


ninenik 1.46.45.xxx 28-04-2017
 ความคิดเห็นที่ 2
เย้ ทำได้แล้วค่ะ ขอบคุณ  @Ninenik  มากๆ เลยค่ะ


tata.com 1.46.111.xxx 30-04-2017 19:52






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ