|
|
|
ช่วยแก้ไขแบบทดสอบออนไลน์ หน่อยครับ ผมทำโปรเจคจบ จะจบแล้วติดแค่ตัวเดียว ช่วยหน่อยนะครับ |
|
|
|
|
|
|
|
อันนี้คือไฟล์เพิ่มแบบทดสอบ ที่แอดมินเป็นคนเพิ่ม
Code (PHP)
<?PHP
session_start();
include('inc/conn_db.php');
include('inc/function.php');
if(!$_SESSION['t_user'])
{
exit("<script>alert('คุณไม่มีสิทธิ์');window.location='index.php';</script>");
}
$tx = "";
if($txtsearch != "")
{
$tx .= "and ( t_name like '%$_GET[txtsearch]%' ) ";
}
//// แสดงว่าเป็น คุณครู
if($_SESSION['t_user'])
{
/// คีย์ของใคร
$sqlz = "select t_id from teacher where t_username = '$_SESSION[t_user]'";
$resultz = mysql_query($sqlz) or die ("error = $sqlz");
$rowz = mysql_fetch_array($resultz);
//echo $_SESSION[t_id];
$tx .= "and (t_username = '$_SESSION[t_user]')";
}
if(!isset($start)){
$start = 0;
}
$limit = '10'; // แสดงผลหน้าละกี่หัวข้อ
$sql = "select * from botrean left join lesson on (botrean.b_id = lesson.b_id) left join teacher on (teacher.t_id = botrean.t_id) left join bottee on (bottee.bt_id = botrean.bt_id) where 1 $tx order by bot_id desc";
$result = mysql_query($sql) or die ("error = $sql");
$num = mysql_num_rows($result);
$sql2 = "select * from botrean left join lesson on (botrean.b_id = lesson.b_id) left join teacher on (teacher.t_id = botrean.t_id) left join bottee on (bottee.bt_id = botrean.bt_id) where 1 $tx order by bot_id desc limit $start,$limit";
$result2 = mysql_query($sql2) or die ("error = $sql2");
?>
<!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" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<script src="gen_validatorv4.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.3.2.min.js"></script>
</head>
<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><?PHP include('head.php'); ?></td>
</tr>
<tr>
<td><table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="5" bgcolor="#FFFFFF"> </td>
<td width="220" bgcolor="#FFFFFF"> </td>
<td width="775" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF" valign="top"><?PHP include('leftmenu.php'); ?></td>
<td align="center" valign="top" bgcolor="#FFFFFF"><p class="fontblack"><a href="managebookques.php" class="link_12_dark_blue">กลับไปหน้าแบบฝึกหัดท้ายบท</a></p>
<form id="formx" name="form1" method="post" action="sql.php" />
<table class="tb" width="750" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td colspan="3" align="center" bgcolor="#006600" class="fontwrt">เพิ่มคำถาม</td>
</tr>
<tr>
<td align="right" valign="top" class="fontblack"> หมวดบทเรียน : </td>
<td colspan="2"><select name="b_id" id="b_id">
<option value="0">โปรดเลือก</option>
<?PHP
$sqlc2 = "select * from lesson";
$resultc2 = mysql_query($sqlc2) or die ("error = $sqlc2");
while ( $rowc2 = mysql_fetch_array($resultc2))
{
?>
<option value="<?PHP echo $rowc2['b_id']; ?>"><?PHP echo $rowc2['b_name']; ?></option>
<?PHP
}
?>
</select><span class="fonred">*</span>
</td>
</tr>
<tr>
<td align="right" valign="top" class="fontblack">บทที่ : </td>
<td colspan="2"><select name="bt_id" id="bt_id">
<option value="0">โปรดเลือก</option>
<?PHP
$sqlc2 = "select * from bottee";
$resultc2 = mysql_query($sqlc2) or die ("error = $sqlc2");
while ( $rowc2 = mysql_fetch_array($resultc2))
{
?>
<option value="<?PHP echo $rowc2['bt_id']; ?>"><?PHP echo $rowc2['bt_name']; ?></option>
<?PHP
}
?>
</select><span class="fonred">*</span></td>
</tr>
<tr>
<td width="208" align="right" valign="top" class="fontblack">คำถาม : </td>
<td width="520" colspan="2"><span class="fonred">
<textarea name="ques_tion" cols="50" rows="3" class="fontblack" id="ques_tion" type="text" /></textarea>
*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="fontblack"> คำตอบ : 1.</td>
<td colspan="2"><span class="fonred"><input name="choice1" type="text" class="fontblack" id="choice1" size="50" />*</span>
</td>
</tr>
<tr>
<td align="right" valign="top" class="fontblack">2.</td>
<td colspan="2"><span class="fonred"><input name="choice2" type="text" class="fontblack" id="choice2" size="50" />*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="fontblack">3.</td>
<td colspan="2"><span class="fonred"><input name="choice3" type="text" class="fontblack" id="choice3" size="50" />*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="fontblack">4.</td>
<td colspan="2"><span class="fonred"><input name="choice4" type="text" class="fontblack" id="choice4" size="50" />*</span></td>
</tr>
<tr>
<td align="right" class="fontblack">คำตอบที่ถูกต้อง : </td>
<td colspan="2"><span class="fonred">
<select name="answer">
<option value="0" selected="selected">- เลือกคำตอบ -</option>
<option value="1">คำตอบที่ 1</option>
<option value="2">คำตอบที่ 2</option>
<option value="3">คำตอบที่ 3</option>
<option value="4">คำตอบที่ 4</option>
</select>*</span>
</td>
</tr>
<tr>
<td> </td>
<td colspan="2"><input type="submit" name="Submit3" value="บันทึก" />
<input name="action" type="hidden" id="action" value="addques" />
<input type="hidden" id="t_id" name="t_id" value="<?php echo $_SESSION['t_id'];?>" />
</td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
</table>
</form>
<script language="JavaScript" type="text/javascript"
xml:space="preserve">//<![CDATA[
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("formx");
frmvalidator.addValidation("ques_tion","req","กรุณาใส่คำถาม");
frmvalidator.addValidation("choice1","req","กรุณาใส่คำตอบที่ 1");
frmvalidator.addValidation("choice2","req","กรุณาใส่คำตอบที่ 2");
frmvalidator.addValidation("choice3","req","กรุณาใส่คำตอบที่ 3");
frmvalidator.addValidation("choice4","req","กรุณาใส่คำตอบที่ 4");
frmvalidator.addValidation("answer","dontselect=0","กรุณาเลือกคำตอบ");
//]]></script>
</td>
</tr>
</table></td>
</tr>
<tr>
<td><?PHP include('footer.php'); ?> </td>
</tr>
</table>
</body>
</html>
อันนี้เป็นไฟล์ตรวจสอบ
Code (PHP)
<?PHP
session_start();
include('inc/conn_db.php');
include('inc/function.php');
$number=1;
if(!$_SESSION['t_user'] and !$_SESSION['s_user'])
{
exit("<script>alert('คุณไม่มีสิทธิ์');window.location='index1.php';</script>");
}
$tx = "";
if($txtsearch != "")
{
$tx .= "and ( t_name like '%$_GET[txtsearch]%' ) ";
}
//// แสดงว่าเป็น คุณครู
if($_SESSION['t_user'])
{
/// คีย์ของใคร
$sqlz = "select t_id from teacher where t_username = '$_SESSION[t_user]'";
$resultz = mysql_query($sqlz) or die ("error = $sqlz");
$rowz = mysql_fetch_array($resultz);
//echo $_SESSION[t_id];
$tx .= "and (t_username = '$_SESSION[t_user]')";
}
if($_SESSION['s_user'])
{
/// คีย์ของใคร
$sqlz = "select s_id from student where s_username = '$_SESSION[s_user]'";
$resultz = mysql_query($sqlz) or die ("error = $sqlz");
$rowz = mysql_fetch_array($resultz);
//echo $_SESSION[t_id];
$tx .= "and (s_username = '$_SESSION[s_user]')";
}
?>
<!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" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<script>
function confirmDelete(delUrl) {
if (confirm("คุณแน่ใจหรือไม่ว่าจะลบ")) {
document.location = delUrl;
}
}
</script>
<script src="gen_validatorv4.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.3.2.min.js"></script>
</head>
<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><?PHP include('head.php'); ?></td>
</tr>
<tr>
<td><table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="5" bgcolor="#FFFFFF"> </td>
<td width="220" bgcolor="#FFFFFF"> </td>
<td width="775" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF" valign="top"><?PHP include('leftmenu.php'); ?></td>
<td align="center" valign="top" bgcolor="#FFFFFF"><p class="fontblack"><a href="index1.php" class="link_12_dark_blue">กลับไปหน้าแรก<img src="images/icon/original_house_icon.gif" width="24" height="24" border="0" /></a></p>
<form method="post" name="quiz">
<table class="tb" width="750" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td colspan="4" align="center" bgcolor="#006600" class="fontwrt">แบบฝึกหัดทดสอบ</td>
</tr>
<?php
$sql="SELECT * FROM question ORDER BY RAND() LIMIT 0,10";
$result = mysql_query($sql) or die ("error = $sql");
while ($row = mysql_fetch_array($result)) {
$ques_id = $row['ques_id'];
$ques_tion = $row['ques_tion'];
$choice1 = $row['choice1'];
$choice2 = $row['choice2'];
$choice3 = $row['choice3'];
$choice4 = $row['choice4'];
?>
<tr>
<td align="right" class="fontblack"> </td>
<td colspan="3" class="fontblack"> </td>
</tr>
<tr>
<td width="190" align="right" class="fontblack">ข้อที่ <?php echo $number; ?> .</td>
<td width="528" colspan="3" class="fontblack"><?PHP echo $ques_tion; ?> </td>
</tr>
<tr>
<td width="190" align="right" class="fontblack"><?php echo "<input type='radio' name='select_$ques_id' value='1'>" ?></td>
<td colspan="3" class="fontblack"><?PHP echo $choice1; ?></td>
</tr>
<tr>
<td width="190" align="right" class="fontblack"><?php echo "<input type='radio' name='select_$ques_id' value='2'>" ?></td>
<td colspan="3" class="fontblack"><?PHP echo $choice2; ?> </td>
</tr>
<tr>
<td width="190" align="right" class="fontblack"><?php echo "<input type='radio' name='select_$ques_id' value='3'>" ?></td>
<td colspan="3" class="fontblack"><?PHP echo $choice3; ?> </td>
</tr>
<tr>
<td align="right" class="fontblack"><?php echo "<input type='radio' name='select_$ques_id' value='4'>" ?></td>
<td colspan="3"><span class="fontblack"><?PHP echo $choice4; ?></span></td>
</tr>
<?php echo "<input type='hidden' name='total_question[]' value='$ques_id'>" ?>
<?php $number++;
}
?>
<tr>
<td align="right" class="fontblack"> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td align="right" class="fontblack"> </td>
<td colspan="3"><input type="submit" value="ส่งคำตอบ"//> <input type="reset" value="ยกเลิก" /></td>
<?
$correct = 0;
$total = count($total_question);
$sql1 = "select ques_id,answer from question order by ques_id";
$result1 = mysql_query($sql1) or die ("error = $sql1");
while ($row1 = mysql_fetch_array($result1)) {
$ques_id = $row1['ques_id'];
$answer = $row1['answer'];
if (@in_array($ques_id, $total_question)) {
$select="select_".$ques_id;
if (${$select}==$answer) {
$correct++;
}
}
}
?>
</tr>
<tr>
<td align="right" class="fontblack"></td>
<td colspan="3"> </td>
</tr>
<tr>
<td align="right" class="fontblack">ผลคะแนน : </td>
<td colspan="3"><?php echo $correct; ?></td>
</tr>
<tr>
<td colspan="4" align="center" class="fontblack">
</td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</td>
</tr>
</table></td>
</tr>
<tr>
<td><?PHP include('footer.php'); ?> </td>
</tr>
</table>
</body>
</html>
อยากให้ user login เข้ามา แล้วทำแบบทดสอบ พอกดส่งคะแนนแล้ว คะแนนก็บันทึกลงฐานข้อมูลของ user แล้วก็พอกดส่งคะแนนแล้วให้ checked ค้างค่าการกดเลือกคำตอบค้างไว้แบบไว้ก่อน แล้วพอกดยกเลิกค่อยเคลีย การ checked เป็นค่าว่าง
Tag : PHP, MySQL, HTML/CSS, JavaScript
|
|
|
|
|
|
Date :
2015-07-12 21:26:32 |
By :
speakphone |
View :
1299 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองสโคบคำถามลงกว่านี้น่ะครับ
|
|
|
|
|
Date :
2015-07-13 17:07:52 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<tr>
<td align="right" class="fontblack">ผลคะแนน : </td>
<td colspan="3"><?php echo $correct; ?></td>
</tr>
จริงๆ แล้วทำแบบทดสอบได้หมดแล้วครับ เพียงแต่อยากให้กดส่งคำตอบแล้วมันบันทึกคะแนนลงฐานข้อมูลเลยแบบนี้อ่ะครับ ไม่ทราบว่าโค้ดข้างบนที่แนบไฟล์ไป พอจะทำได้ไหม
|
|
|
|
|
Date :
2015-07-14 21:56:36 |
By :
speakphone |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
นี่คือหน้าตาครับ
Code (PHP)
<form method="post" name="quiz">
<table class="tb" width="750" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td colspan="4" align="center" bgcolor="#006600" class="fontwrt">แบบฝึกหัดทดสอบ</td>
</tr>
<?php
$sql="SELECT * FROM question ORDER BY RAND() LIMIT 0,10";
$result = mysql_query($sql) or die ("error = $sql");
while ($row = mysql_fetch_array($result)) {
$ques_id = $row['ques_id'];
$ques_tion = $row['ques_tion'];
$choice1 = $row['choice1'];
$choice2 = $row['choice2'];
$choice3 = $row['choice3'];
$choice4 = $row['choice4'];
?>
<tr>
<td align="right" class="fontblack"> </td>
<td colspan="3" class="fontblack"> </td>
</tr>
<tr>
<td width="190" align="right" class="fontblack">ข้อที่ <?php echo $number; ?> .</td>
<td width="528" colspan="3" class="fontblack"><?PHP echo $ques_tion; ?> </td>
</tr>
<tr>
<td width="190" align="right" class="fontblack"><?php echo "<input type='radio' name='select_$ques_id' value='1'>" ?></td>
<td colspan="3" class="fontblack"><?PHP echo $choice1; ?></td>
</tr>
<tr>
<td width="190" align="right" class="fontblack"><?php echo "<input type='radio' name='select_$ques_id' value='2'>" ?></td>
<td colspan="3" class="fontblack"><?PHP echo $choice2; ?> </td>
</tr>
<tr>
<td width="190" align="right" class="fontblack"><?php echo "<input type='radio' name='select_$ques_id' value='3'>" ?></td>
<td colspan="3" class="fontblack"><?PHP echo $choice3; ?> </td>
</tr>
<tr>
<td align="right" class="fontblack"><?php echo "<input type='radio' name='select_$ques_id' value='4'>" ?></td>
<td colspan="3"><span class="fontblack"><?PHP echo $choice4; ?></span></td>
</tr>
<?php echo "<input type='hidden' name='total_question[]' value='$ques_id'>" ?>
<?php $number++;
}
?>
<tr>
<td align="right" class="fontblack"> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td align="right" class="fontblack"> </td>
<td colspan="3"><input type="submit" value="ส่งคำตอบ"//> <input type="reset" value="ยกเลิก" /></td>
<?
$correct = 0;
$total = count($total_question);
$sql1 = "select ques_id,answer from question order by ques_id";
$result1 = mysql_query($sql1) or die ("error = $sql1");
while ($row1 = mysql_fetch_array($result1)) {
$ques_id = $row1['ques_id'];
$answer = $row1['answer'];
if (@in_array($ques_id, $total_question)) {
$select="select_".$ques_id;
if (${$select}==$answer) {
$correct++;
}
}
}
?>
</tr>
<tr>
<td align="right" class="fontblack"></td>
<td colspan="3"> </td>
</tr>
<tr>
<td align="right" class="fontblack">ผลคะแนน : </td>
<td colspan="3"><?php echo $correct; ?></td>
</tr>
<tr>
<td colspan="4" align="center" class="fontblack">
</td>
</tr>
</table>
</form>
นี่คือแบบฟอร์มเช็คคำตอบครับ แล้วผมอยากล็อกอินเข้ามาแล้วทำแบบทดสอบ แล้วกดส่ง แล้วบันทึกคะแนนที่ได้ ลงไปในฐานข้อมูลของสมาชิกเลยอ่ะครับ
Code (PHP)
<?PHP
session_start();
include('inc/conn_db.php');
include('inc/function.php');
$number=1;
if(!$_SESSION['t_user'] and !$_SESSION['s_user'])
{
exit("<script>alert('คุณไม่มีสิทธิ์');window.location='index1.php';</script>");
}
$tx = "";
if($txtsearch != "")
{
$tx .= "and ( t_name like '%$_GET[txtsearch]%' ) ";
}
//// แสดงว่าเป็น คุณครู
if($_SESSION['t_user'])
{
/// คีย์ของใคร
$sqlz = "select t_id from teacher where t_username = '$_SESSION[t_user]'";
$resultz = mysql_query($sqlz) or die ("error = $sqlz");
$rowz = mysql_fetch_array($resultz);
//echo $_SESSION[t_id];
$tx .= "and (t_username = '$_SESSION[t_user]')";
}
if($_SESSION['s_user'])
{
/// คีย์ของใคร
$sqlz = "select s_id from student where s_username = '$_SESSION[s_user]'";
$resultz = mysql_query($sqlz) or die ("error = $sqlz");
$rowz = mysql_fetch_array($resultz);
//echo $_SESSION[t_id];
$tx .= "and (s_username = '$_SESSION[s_user]')";
}
?>
ตรวจสอบสมาชิก
|
|
|
|
|
Date :
2015-07-14 22:14:03 |
By :
speakphone |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|