สอบถาม เรื่อง การนับค่าที่ได้จาก echo ซึ่งเป็นข้อมูลที่ได้จากการประมวลผลเรียบร้อยแล้ว
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถาม เรื่อง การนับค่าที่ได้จาก echo ซึ่งเป็นข้อมูลที่ได้จากการประมวลผลเรียบร้อยแล้ว
สอบถาม เรื่อง การนับค่าที่ได้จาก echo ซึ่งเป็นข้อมูลที่ได้จากการประมวลผลเรียบร้อยแล้ว
สอบถามเกี่ยวกับ การนับจำนวนข้อมูลที่ผ่านการคิวรี่ จากหลายตาราง มาทำการคำนวณ และแสดงผลออกมาecho แล้ว จะมีวิธีการนับอย่างไรค่ะ
อันนี้เป็น code
อันนี้เป็น code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | 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> |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
ลองสร้างเป็น array 3 มิติเข้าไปเก็บค่า แล้วค่อยใช้คำสั่ง count() นับจำนวน
เช่น
1 | $arr_case [ 'normal' ][ด้านที่][ไอดีนักเรียน]=1; |
สมมติในส่วนด้านที่ 1
1 2 3 4 5 6 7 8 | <? if ( $a1 <=3){ echo "= ปกติ" ; } elseif ( $a1 <=4){ echo "= เสี่ยง" ; } elseif ( $a1 >4){ echo "= ปัญหา" ; } ?> |
ก็ใส่เป็น
1 2 3 4 5 6 7 8 9 10 11 | <? 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
1 2 3 | <?=(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 , .....

ความคิดเห็นที่
2


ขอบคุณทุกการสนับสนุน
![]()