<?php
session_start();
if($_SESSION['code'] == "")
{
echo"Please Login!";
}
mysql_connect("localhost","root","");
mysql_select_db("choice");
$strSQL = "SELECT * FROM user WHERE code = '".$_SESSION['code']."'";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ผลการทดสอบ</title>
</head>
<body>
ชื่อผู้เข้าสอบ: <?php echo $objResult["name"];?><br>
<?php
//$thisUserName = trim($_POST["usrName"]);
$subjName = $_POST["subjName"];
$cutpoint = $_POST["cpoint"];
$correctAns = $_POST["result"];
// $correctAns เป็น Array ประกอบด้วย คำตอบที่ถูก ที่ส่งมาจากตัวข้อสอบ
$numOfQstns = sizeof($correctAns);
$score = 0;
// รับคำตอบ
for ($i=1; $i<=$numOfQstns; $i++)
{
$stAns[$i-1] = trim($_POST["question" . $i]);
}
// ตรวจคำตอบ
for ($i=0; $i<=($numOfQstns-1); $i++)
{
$correct = $correctAns[$i];
$stAnswer = $stAns[$i];
if($stAnswer == $correct) {
$score++;
};
};
$percentage = number_format($score/$numOfQstns*100, 2, '.', '');
//echo "ชื่อผู้ทำข้อสอบ: $name<br>";
echo "ข้อสอบวิชา: $subjName <br>";
echo"ทำข้อสอบได้ทั้งหมด: $score ข้อ จากทั้งหมด 61 ข้อ คิดเป็นร้อยละ $percentage %<br>";
echo "<br><br><b>ผลการสอบ</b>";
if($percentage >=$cutpoint)
{
echo "<br> ผ่าน";
}
else
{
echo "<br><span style=\"color: #f00;\"> ท่านไม่ผ่านเกณฑ์ $cutpoint %</span>";
}
?>
</body>
</html>
php mysql ต้องการเก็บค่า ชื่อ คะแนน และวันที่ล่าสุดลง table ที่เตรียมเอาไว้ ควรเขียนอย่างไร รบกวนผู้รู้ครับ
session_start();
if($_SESSION['code'] == "")
{
echo"Please Login!";
}
mysql_connect("localhost","root","");
mysql_select_db("choice");
$strSQL = "SELECT * FROM user WHERE code = '".$_SESSION['code']."'";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ผลการทดสอบ</title>
</head>
<body>
ชื่อผู้เข้าสอบ: <?php echo $objResult["name"];?><br>
<?php
//$thisUserName = trim($_POST["usrName"]);
$subjName = $_POST["subjName"];
$cutpoint = $_POST["cpoint"];
$correctAns = $_POST["result"];
// $correctAns เป็น Array ประกอบด้วย คำตอบที่ถูก ที่ส่งมาจากตัวข้อสอบ
$numOfQstns = sizeof($correctAns);
$score = 0;
// รับคำตอบ
for ($i=1; $i<=$numOfQstns; $i++)
{
$stAns[$i-1] = trim($_POST["question" . $i]);
}
// ตรวจคำตอบ
for ($i=0; $i<=($numOfQstns-1); $i++)
{
$correct = $correctAns[$i];
$stAnswer = $stAns[$i];
if($stAnswer == $correct) {
$score++;
};
};
$percentage = number_format($score/$numOfQstns*100, 2, '.', '');
//echo "ชื่อผู้ทำข้อสอบ: $name<br>";
echo "ข้อสอบวิชา: $subjName <br>";
echo"ทำข้อสอบได้ทั้งหมด: $score ข้อ จากทั้งหมด 61 ข้อ คิดเป็นร้อยละ $percentage %<br>";
echo "<br><br><b>ผลการสอบ</b>";
if($percentage >=$cutpoint)
{
echo "<br> ผ่าน";
}
else
{
echo "<br><span style=\"color: #f00;\"> ท่านไม่ผ่านเกณฑ์ $cutpoint %</span>";
}
?>
</body>
</html>