|
|
|
แบบทดสอบออนไลน์ random ข้อสอบ ตรวจคำตอบแล้วไม่ได้ครับ เช็คข้อที่ random คำตอบข้อนั้นได้ |
|
|
|
|
|
|
|
Code (PHP)
<div align="left">
<form id="form1" name="form1" method="post" action="addans.php" enctype="multipart/form-data">
<br />
<?
$sql2= "select * from test where subjects='$codesu' and type='2' order by rand() limit 0,2";
$result2=mysql_query($sql2);
$numrows2=mysql_num_rows($result2);
$i2=0;
while( $i2<$numrows2){
$fetch2=mysql_fetch_array($result2);
$dbid=$fetch2['id'];
$dbquestion=$fetch2['question'];
$dboptions1=$fetch2['options1'];
$dboptions2=$fetch2['options2'];
$dboptions3=$fetch2['options3'];
$dboptions4=$fetch2['options4'];
?>
คำถาม :
<?
$loadcontentda = "data/$dbquestion";
$fpda = @fopen($loadcontentda, "r");
$loadcontentda = @fread($fpda, @filesize($loadcontentda));
$loadcontentda = htmlspecialchars($loadcontentda);
$Detailda = stripslashes(FixQuotes($loadcontentda));
@fclose($fpda);
?>
<?=$Detailda ;?><br />
<?
$loadopt1 = "data/$dboptions1";
$fopt1 = @fopen($loadopt1, "r");
$loadopt1 = @fread($fopt1, @filesize($loadopt1));
$loadopt1 = htmlspecialchars($loadopt1);
$Detailopt1 = stripslashes(FixQuotes($loadopt1));
@fclose($fopt1);
?>
คำตอบ
<input name="ans<?=$dbid;?>" type="radio" value="1" />
ที่ 1 :
<?=$Detailopt1 ;?><br />
<?
$loadopt2 = "data/$dboptions2";
$fopt2 = @fopen($loadopt2, "r");
$loadopt2 = @fread($fopt2, @filesize($loadopt2));
$loadopt2 = htmlspecialchars($loadopt2);
$Detailopt2 = stripslashes(FixQuotes($loadopt2));
@fclose($fopt2);
?>
คำตอบ
<input name="ans<?=$dbid;?>" type="radio" value="2" />
ที่ 2 :<?=$Detailopt2 ;?><br />
<?
$loadopt3 = "data/$dboptions3";
$fopt3 = @fopen($loadopt3, "r");
$loadopt3 = @fread($fopt3, @filesize($loadopt3));
$loadopt3 = htmlspecialchars($loadopt3);
$Detailopt3 = stripslashes(FixQuotes($loadopt3));
@fclose($fopt3);
?>
คำตอบ
<input name="ans<?=$dbid;?>" type="radio" value="3" />
ที่ 3 :<?=$Detailopt3 ;?><br />
<?
$loadopt4 = "data/$dboptions4";
$fopt4 = @fopen($loadopt4, "r");
$loadopt4 = @fread($fopt4, @filesize($loadopt4));
$loadopt4 = htmlspecialchars($loadopt4);
$Detailopt4 = stripslashes(FixQuotes($loadopt4));
@fclose($fopt4);
?>
คำตอบ
<input name="ans<?=$dbid;?>" type="radio" value="4" />
ที่ 4 :<?=$Detailopt4 ;?>
<input type='hidden' name='id' value='<?=$dbid;?>'>
<hr />
<? $i2++; } ?>
<p>
<input type="submit" name="Submit" value=" ส่งคำตอบ " />
<input type="reset" name="Reset" value="Reset" />
</p>
</form>
</div>
[font=Verdana]โค๊ดดึงข้อสอบ ออกมาครับ ทำงานได้
ผมอยากตรวจคำตอบต้องเขียนโค๊ดอย่างไรครับ[/font]
Code (PHP)
<?
include("connectserver.php");
$sqlAns= "select * from test where type='2' ";
$resultAns=mysql_query($sqlAns);
$numrowsAns=mysql_num_rows($resultAns);
while( $fetchAns=mysql_fetch_array($resultAns)){
$dbid=$fetchAns['id'];
$answer=$fetchAns['reply'];
$select="ans".$dbid;
if(${$select}==$answer){
$correct++;
}
}
echo "$correct-$ansid";
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-04-20 23:48:55 |
By :
libservice |
View :
2127 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
include("connectserver.php");
$correct=0;
$total=count($_REQUEST['totalans']);
$sqlAns= "select id, reply from test ";
$resultAns=mysql_query($sqlAns);
$numrowsAns=mysql_num_rows($resultAns);
while( $fetchAns=mysql_fetch_array($resultAns)){
$id=$fetchAns['id'];
$answer=$fetchAns['reply'];
if (in_array($id, $_REQUEST['totalans'])){
$select=$_REQUEST['ans'.$id];
if ($select==$answer) {
$correct++ ;
}
}
}
echo "ทำถูกต้อง $correct ข้อ จากทั้งหมด $total ข้อ";
?>
ค้นหาจนใด้ครับ ขอบคุณ www.thaicreate.com
|
|
|
|
|
Date :
2011-04-21 00:53:33 |
By :
libservice |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<div align="left">
<form id="form1" name="form1" method="post" action="addans.php" enctype="multipart/form-data">
<br />
<?
$sql2= "select * from test where subjects='$codesu' and type='2' order by rand() limit 0,2";
$result2=mysql_query($sql2);
$numrows2=mysql_num_rows($result2);
$i2=0;
while( $i2<$numrows2){
$fetch2=mysql_fetch_array($result2);
$dbid=$fetch2['id'];
$dbquestion=$fetch2['question'];
$dboptions1=$fetch2['options1'];
$dboptions2=$fetch2['options2'];
$dboptions3=$fetch2['options3'];
$dboptions4=$fetch2['options4'];
?>
คำถาม :
<?
$loadcontentda = "data/$dbquestion";
$fpda = @fopen($loadcontentda, "r");
$loadcontentda = @fread($fpda, @filesize($loadcontentda));
$loadcontentda = htmlspecialchars($loadcontentda);
$Detailda = stripslashes(FixQuotes($loadcontentda));
@fclose($fpda);
?>
<?=$Detailda ;?><br />
<?
$loadopt1 = "data/$dboptions1";
$fopt1 = @fopen($loadopt1, "r");
$loadopt1 = @fread($fopt1, @filesize($loadopt1));
$loadopt1 = htmlspecialchars($loadopt1);
$Detailopt1 = stripslashes(FixQuotes($loadopt1));
@fclose($fopt1);
?>
คำตอบ
<input name="ans<?=$dbid;?>" type="radio" value="1" />
ที่ 1 :
<?=$Detailopt1 ;?><br />
<?
$loadopt2 = "data/$dboptions2";
$fopt2 = @fopen($loadopt2, "r");
$loadopt2 = @fread($fopt2, @filesize($loadopt2));
$loadopt2 = htmlspecialchars($loadopt2);
$Detailopt2 = stripslashes(FixQuotes($loadopt2));
@fclose($fopt2);
?>
คำตอบ
<input name="ans<?=$dbid;?>" type="radio" value="2" />
ที่ 2 :<?=$Detailopt2 ;?><br />
<?
$loadopt3 = "data/$dboptions3";
$fopt3 = @fopen($loadopt3, "r");
$loadopt3 = @fread($fopt3, @filesize($loadopt3));
$loadopt3 = htmlspecialchars($loadopt3);
$Detailopt3 = stripslashes(FixQuotes($loadopt3));
@fclose($fopt3);
?>
คำตอบ
<input name="ans<?=$dbid;?>" type="radio" value="3" />
ที่ 3 :<?=$Detailopt3 ;?><br />
<?
$loadopt4 = "data/$dboptions4";
$fopt4 = @fopen($loadopt4, "r");
$loadopt4 = @fread($fopt4, @filesize($loadopt4));
$loadopt4 = htmlspecialchars($loadopt4);
$Detailopt4 = stripslashes(FixQuotes($loadopt4));
@fclose($fopt4);
?>
คำตอบ
<input name="ans<?=$dbid;?>" type="radio" value="4" />
ที่ 4 :<?=$Detailopt4 ;?>
<input type='hidden' name='totalans[]' value='<?=$dbid;?>'>
<hr />
<? $i2++; } ?>
<p>
<input type="submit" name="Submit" value=" ส่งคำตอบ " />
<input type="reset" name="Reset" value="Reset" />
</p>
</form>
</div>
|
|
|
|
|
Date :
2011-04-21 00:56:07 |
By :
libservice |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอ Code แบบเต็ม ๆ เลยได้ไหมครับ กำลังต้องการนำไปทดสอบเด็ก ๆ อยู่เลยครับ
|
|
|
|
|
Date :
2012-02-09 18:56:51 |
By :
ครูประถม |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|