จะสุ่มข้อสอบจะเขียนโค้ดอย่างไร จะสุ่มข้อสอบจะเขียนโค้ดอย่างไร
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer ORDER BY RAND() LIMIT 2 ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>
Date :
2009-04-25 11:17:54
By :
webmaster
random.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>ข้อสอบออนไลน์</title>
</head>
<body>
<b>ข้อสอบให้เลือกตอบข้อที่ถูกต้อง<b/>
<form method="post" action="random_check.php">
<?
$number=1;
require"connect.php";
$sql="select * from tb_test order by rand() limit 0,5";
$result=mysql_db_query("$dbname",$sql);
while ($r=mysql_fetch_array($result)){
$id=$r[id];
$question=$r[question];
$choice1=$r[choice1];
$choice2=$r[choice2];
$choice3=$r[choice3];
$choice4=$r[choice4];
echo"<b>$number. $question</b><br>
<input type='radio' name='select_$id' value='1'>
$choice1<br>
<input type='radio' name='select_$id' value='2'>
$choice2<br>
<input type='radio' name='select_$id' value='3'>
$choice3<br>
<input type='radio' name='select_$id' value='4'>
$choice4
<input type='hidden' name='total_question[]' value='$id'<br>
<hr>";
$number++;
}
?>
<input type="submit" value="submit"><input type="reset" value="reset">
</form>
</body>
</html>
random_check.php
<?
$correct=0;
$total=count($total_question);
require"connect.php";
$sql="select id, answer from tb_test order by id";
$result=mysql_db_query("$dbname",$sql);
while ($r=mysql_fetch_array($result)){
$id=$r[id];
$answer=$r[answer];
if (in_array($id, $total_question)){
$select="select_".$id;
if (${$select}==$answer) {
$correct++;
}
}
}
echo"<h2>ถูกต้องทั้งหมด $correct ข้อ <br>
ข้อสอบทั้งหมด $total ข้อ </h2>";
?>
Date :
2010-01-04 10:36:27
By :
ซอฟต์แวร์แอลพี
มีฐานข้อมูล ไหมครับ ช่วยโพสแจก หน่วย
ประวัติการแก้ไข 2011-06-27 17:13:01
Date :
2011-06-27 17:12:30
By :
item170
Load balance : Server 00