การ ทำแบบทดสอบค่ะ ช่วยดูให้หน่อยนะคะ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา การ ทำแบบทดสอบค่ะ ช่วยดูให้หน่อยนะคะ
การ ทำแบบทดสอบค่ะ ช่วยดูให้หน่อยนะคะ
คือ ตอนนี้ ไม่ได้เก็บรูปลงฐานข้อมูลแล้วค่ะ ไม่ได้เรียกไฟล์ใดๆอะไรเลย
แค่ Input รูปภาพลงไปในฟอร์ม แล้วอยากทราบว่าโค้ดนี้ การตั้งชื่อของภาพเพื่อนำไปเช็คกับคะแนนผิดตรงไหนรึปล่าวคะ?
พอทดสอบ ถึงจะคลิกรูปที่ถูก หรือผิด มันก็จะโชว์คะแนน 1 ตลอดเลยค่ะ
*** คะแนนที่โชว์จะขึ้นอยู่กับการ แรนดอม คำถามเลยค่ะ ***
ช่วยเช็คให้ทีนะคะ
ไฟล์ sample1 ค่ะ
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 | <html> <body> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <form name= "form1" method= "post" action= "Sample2.php" > <? $host = "127.0.0.1" ; $username = "root" ; $password = "1234" ; $db = "game" ; $tb = "tlc" ; mysql_connect( $host , $username , $password ) or die ( "ติดต่อกับฐานข้อมูล Mysql ไม่ได้ " ); mysql_select_db( $db ) or die ( "เลือกฐานข้อมูลไม่ได้" ); mysql_query( "SET NAMES UTF8" ); $sql = "Select * From $tb order by rand() limit 1" ; $db_query =mysql_query( $sql ); $i =0; while ( $result =mysql_fetch_array( $db_query )) { $i ++; ?> <table width= "64%" border= "0" align= "center" > <tr> <td width= "18%" > <div align= "center" > <input name= "id[<?=$i;?>]" type= "hidden" value= "<?=$result[" id "];?>" > <?= $result [ "vocab" ];?> </div></td> <td width= "14%" > <input type= "image" name= "c<?=$i;?>" id= "c<?=$i;?>" src= "picgame/tlcpic1.png" > </td> <td width= "16%" > <input type= "image" name= "c<?=$i;?>" id= "c<?=$i;?>" src= "picgame/tlcpic2.png" > </td> <td width= "16%" > <input type= "image" name= "c<?=$i;?>" id= "c<?=$i;?>" src= "picgame/tlcpic3.png" > </td> <td width= "15%" ><input type= "image" name= "c<?=$i;?>" id= "c<?=$i;?>" src= "picgame/tlcpic4.png" > <input name= "answer[<?=$i;?>]" type= "hidden" value= "<?=$result[" answer "];?>" > </td> </tr> </table> <? } mysql_close(); ?> <div align= "center" ><br> <input type= "hidden" name= "line" value= "<?=$i;?>" > <input type= "submit" name= "Submit" value= "ตรวจคะแนน" > </div> </form> </body> </html> |
ไฟล์ Sample2 ค่ะ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <? mysql_query( "set NAMES UTF8" ); $score =0; for ( $i =1; $i <= $_POST [ "line" ]; $i ++) { If( $_POST [ "c$i" ] == $_POST [ "answer$i" ]) { $score = $score +1; } } echo "True $score<br>" ; ?> |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
ตัวแปร input type image เวลาส่งค่าไป ชื่อตัวเแปร จะมี _x หรือ _y
เช่น
1 | <input type= "image" name= "c1" id= "c1" src= "picgame/tlcpic4.png" > |
ค่าที่เราเช็ค จะต้องเป็น $_POST['c1_x'] หรือ $_POST['c1_y']

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