 |
ผมมีปัญหาเรื่องการทำแบบทดสอบ online อยากขอคำแนะนำด้วยครับ |
|
 |
|
|
 |
 |
|
ผมได้ทำการสร้างแบบทดสอบ online ขึ้นมาและทดลองการรันบนเครื่องของตนเองที่จำลองเป็น server (localhost) การทดสอบนั้นเป็นไปด้วยดีไม่มีปัญหาใดๆ ระบบสามารถตรวจคำตอบให้ได้ถูกต้อง แสดงคะแนนที่ได้และบันทึกคะแนนลงฐานข้อมูลให้ ประมาณว่างานทั้งหมดที่สร้างขึ้นนั้นสำเร็จ และเสร็จเรียบร้อย
แต่ เมื่อผมนำข้อมูลเว็บไซต์ทั้งหมด upload ขึ้นสู่ hosting ที่ผมเช่าเอาไว้ กลับเจอปัญหาในส่วนของการตรวจคำตอบ โดยผมลองทำแบบทดสอบและคลิกปุ่มส่งคำตอบ ปรากฏว่า คะแนนสอบเป็น 0 คะแนน ซึ่งตอนทดสอบในเครื่องตนเองนั้นไม่มีปัญหาแต่อย่างใด เหมือนกับว่าสคริปต์มันไม่ตรวจคำตอบให้เลย
นี่เป็นตัวอย่างสคริปต์บางส่วนของไฟล์แสดงแบบทดสอบ โดยนำแบบทดสอบบางส่วนจากฐานข้อมูลมาแสดงบนหน้าเว็บเพจ
<?
$number = 1;
mysql_connect($dbhost,$dbuser,$dbpass) or die ("เชื่อมต่อ MySQL ไม่ได้");
mysql_query("set NAMES tis620");
$sql = "Select * From tbtest order by id limit 0,30";
$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 "ข้อ $number. $question <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 <hr>";
$number++;
}
?>
จากตัวอย่าง ผมสั่งให้แสดงข้อสอบ 30 ข้อ ข้อสอบถูกแสดงออกมาอย่างถูกต้องไม่มีปัญหา
เมื่อเริ่มทำแบบทดสอบและคลิกปุ่ม ส่งคำตอบ สคริปต์ตรวจสอบคำตอบจะทำงานเพื่อตรวจสอบว่า ทำข้อสอบถูกต้องทั้งหมดกี่ข้อ โดยจะแสดงจำนวนข้อสอบที่ทำถูก จำนวนข้อสอบทั้งหมด พร้อมกับบันทึกคะแนนลงในฐานข้อมูล
นี่เป็นตัวอย่างสคริปต์ตรวจสอบคำตอบ
<?
$score = 0;
$total = 0;
mysql_connect($dbhost,$dbuser,$dbpass) or die ("เชื่อมต่อ MySQL ไม่ได้");
mysql_select_db($dbname) or die ("เลือกฐานข้อมูลไม่ได้");
mysql_query("set NAMES tis620");
$sql = "Select id,answer From tbtest order by id limit 0,30";
$dbquery = mysql_db_query($dbname,$sql);
$total = mysql_num_rows($dbquery);
while ($result = mysql_fetch_array($dbquery))
{
$id = $result[id];
$answer = $result[answer];
$select = "select_".$id;
if(${$select}==$answer)
{
$score++;
}
}
echo "คุณทำข้อสอบถูกต้องทั้งหมด $score ข้อ <br>จากข้อสอบทั้งหมด $total ข้อ";
$sql = "UPDATE tbstudent Set pre_test = '$score' WHERE user = '$username'";
mysql_query($sql);
mysql_close();
if($score>=10)
{
echo "<p><div align='center'>คุณทำแบบทดสอบผ่านเกณฑ์ตามที่กำหนด</a> ระบบได้ทำการจัดเก็บคะแนนของคุณเรียบร้อยแล้ว<br>";
echo "<a href='home.php'>เข้าสู่บทเรียน</a></div>";
} else {
echo "<p><div align='center'>คุณทำแบบทดสอบไม่ผ่านเกณฑ์<br><a href='pre_test.php'>กลับไปทำแบบทดสอบใหม่อีกครั้ง</a></div>";
}
?>
จากสคริปต์ เมื่อส่งคำตอบปรากฏว่า คุณทำข้อสอบไม่ถูกต้อง ซึ่งไม่ว่าจะเลือก choice ใดของข้อสอบข้อนั้น คะแนนก็ยังคงเป้น 0 เหมือนเดิม
ผมจึงอยากจะรบกวนถามว่า มันเกิดจากสาเหตุใด ทำไมตอนทดสอบในเครื่องไม่มีปัญหา แต่บน hosting กลับมีปัญหา ทั้งๆ ที่ ผมเปลี่ยนชื่อ host name, database name, user และ password ตามที่ hosting ให้มาแล้ว รบกวนช่วยตอบด้วยนะครับ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-05-25 16:49:31 |
By :
myjayday |
View :
2190 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บนโฮสที่คุณเช่า คงไม่ได้เปิด register_globals = On ไว้น่ะครับ
ทางแก้คือ เวลาเรียกตัวแปรที่มาจากการ ส่งผ่านจาก form ให้เรียกแบบนี้ครับ
Code (PHP)
<?php
$var = $_GET["var"]; // แบบ get
$var = $_POST["var"]; // แบบ post
$var = $_REQUEST["var"];// ได้ทั้ง get และ post
?>
จากงานของคุณ ก็เปลี่ยนเป็น
Code (PHP)
<?php
$select = $_POST["select_".$id];
if($select==$answer)
?>
|
 |
 |
 |
 |
Date :
2009-05-25 18:16:14 |
By :
lozomac |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าคุณอยากเรียก ตัวแปรแบบ register on แล้วก็ต้อง import เข้ามาด้วยฟังชั่น
import_request_variables('gp'); // g = GET, p = POST
ก็ได้คับ
ตย.
import_request_variables('gp');
echo $select_1;
//$echo $_POST['select_1'];
|
 |
 |
 |
 |
Date :
2009-05-25 18:21:24 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?
$number = 1;
mysql_connect($dbhost,$dbuser,$dbpass) or die ("เชื่อมต่อ MySQL ไม่ได้");
mysql_query("set NAMES tis620");
$sql = "Select * From tbtest order by id limit 0,30";
$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 "ข้อ $number. $question <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 <hr>";
$number++;
}
?>
<?
$score = 0;
$total = 0;
mysql_connect($dbhost,$dbuser,$dbpass) or die ("เชื่อมต่อ MySQL ไม่ได้");
mysql_select_db($dbname) or die ("เลือกฐานข้อมูลไม่ได้");
mysql_query("set NAMES tis620");
$sql = "Select id,answer From tbtest order by id limit 0,30";
$dbquery = mysql_db_query($dbname,$sql);
$total = mysql_num_rows($dbquery);
while ($result = mysql_fetch_array($dbquery))
{
$id = $result["id"];
$answer = $result["answer"];
$select = "select_".$id;
if(${$select}==$answer)
{
$score++;
}
}
echo "คุณทำข้อสอบถูกต้องทั้งหมด $score ข้อ <br>จากข้อสอบทั้งหมด $total ข้อ";
$sql = "UPDATE tbstudent Set pre_test = '$score' WHERE user = '$username'";
mysql_query($sql);
mysql_close();
if($score>=10)
{
echo "<p><div align='center'>คุณทำแบบทดสอบผ่านเกณฑ์ตามที่กำหนด</a> ระบบได้ทำการจัดเก็บคะแนนของคุณเรียบร้อยแล้ว<br>";
echo "<a href='home.php'>เข้าสู่บทเรียน</a></div>";
} else {
echo "<p><div align='center'>คุณทำแบบทดสอบไม่ผ่านเกณฑ์<br><a href='pre_test.php'>กลับไปทำแบบทดสอบใหม่อีกครั้ง</a></div>";
}
?>
ลองดูครับ
|
 |
 |
 |
 |
Date :
2009-05-25 18:29:20 |
By :
Nunabi |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณมากๆ เลยนะครับ  
ผมขอให้คะแนนเป็นการขอบคุณก็แล้วกันนะครับ
|
 |
 |
 |
 |
Date :
2009-05-26 18:18:44 |
By :
myjayday |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยหน่อยคะ จากโค้ดนี้ คำตอบจะออกมาทีละข้อแล้วให่กดnext ถึงจะเปลี่ยนข้อใหม่ และเมื่อทำการตอบคำถามหากผิดดก็จะ popup ขึ้นมาว่าผิดเลยคะ ช่วยแก้เป็นให้เรียกมาทีเดียวเลยสิบข้อ และตอบให้เส็ดหมดทุกข้อก่อนค่อย submit ตรวจคำตอบ และบอกว่าข้อไหนผิดค่ะ ขอบคุณล่วงหน้านะคะ
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Elearning
{
public partial class sSubjectTest : System.Web.UI.Page
{
protected string PostBackStr;
public string TestID;
DBConnect DB = new DBConnect();
protected void Page_Load(object sender, EventArgs e)
{
txtName.Text = Session["Name"].ToString();
PostBackStr = Page.ClientScript.GetPostBackEventReference(this, "time");
if (IsPostBack)
{
TestID = Request.QueryString["TestID"].ToString();
string eventArg = Request["__EVENTARGUMENT"];
if (eventArg == "time")
{
getNextQuestion();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Visible = false;
txtName.Visible = false;
Button1.Visible = false;
Panel1.Visible = true;
lblName.Text = "Name : " + txtName.Text;
int score = Convert.ToInt32(txtScore.Text);
lblScore.Text = "Score : " + Convert.ToString(score);
Session["counter"] = "1";
Random rnd = new Random();
int i = rnd.Next(1, 10);//Here specify your starting slno of question table and ending no.
//lblQuestion.Text = i.ToString();
getQuestion(i);
}
protected void Button2_Click(object sender, EventArgs e)
{
getNextQuestion();
}
public void getQuestion(int no)
{
string str = "select * from [QA] where TestID = " + TestID;
//SqlDataAdapter da2 = new SqlDataAdapter(str, sqlconn);
DataSet ds2 = new DataSet();
//da2.Fill(ds2, "Question");
ds2 = DB.QueryDataSet(str);
if (ds2.Tables[0].Rows.Count > 0)
{
DataRow dtr;
int i = 0;
while (i < ds2.Tables[0].Rows.Count)
{
dtr = ds2.Tables[0].Rows[i];
Session["Answer"] = Convert.ToString(Convert.ToInt32(dtr["Correct"].ToString()) - 1);
Session["Marker"] = dtr["Marker"].ToString();
lblQuestion.Text = "Q." + Session["counter"].ToString() + " " + dtr["Question"].ToString();
RblOption.ClearSelection();
RblOption.Items.Clear();
RblOption.Items.Add(dtr["Option1"].ToString());
RblOption.Items.Add(dtr["Option2"].ToString());
RblOption.Items.Add(dtr["Option3"].ToString());
RblOption.Items.Add(dtr["Option4"].ToString());
i++;
}
}
DB.Close();
getNextQuestion();
}
public void getNextQuestion()
{
if (Convert.ToInt32(Session["counter"].ToString()) < 10)//10 is a counter which is used for 10 questions
{
if (RblOption.SelectedIndex >= 0)
{
if (Session["Answer"].ToString() == RblOption.SelectedIndex.ToString())
{
int score = Convert.ToInt32(txtScore.Text) + 1;// 1 for mark for each question
// txtScore.Text = score.ToString();
lblScore.Text = "Score : " + Convert.ToString(score);
}
else
{
string a = "<script>alert('คุณตอบผิดค่ะ คำอธิบายข้อนี้คือ " + Session["Marker"].ToString() + "')</script>";
Response.Write(a);
}
}
Random rnd = new Random();
int i = rnd.Next(1, 10);
//lblQuestion.Text = i.ToString();
getQuestion(i);
Session["counter"] = Convert.ToString(Convert.ToInt32(Session["counter"].ToString()) + 1);
}
else
{
Panel2.Visible = false;
//code for displaying after completting the exam, if you want to show the result then you can code here.
}
}
}
}
|
 |
 |
 |
 |
Date :
2011-03-05 19:12:15 |
By :
เด็กฉลาดน้อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (ASP)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Elearning
{
public partial class sSubjectTest : System.Web.UI.Page
{
protected string PostBackStr;
public string TestID;
DBConnect DB = new DBConnect();
protected void Page_Load(object sender, EventArgs e)
{
txtName.Text = Session["Name"].ToString();
PostBackStr = Page.ClientScript.GetPostBackEventReference(this, "time");
if (IsPostBack)
{
TestID = Request.QueryString["TestID"].ToString();
string eventArg = Request["__EVENTARGUMENT"];
if (eventArg == "time")
{
getNextQuestion();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Visible = false;
txtName.Visible = false;
Button1.Visible = false;
Panel1.Visible = true;
lblName.Text = "Name : " + txtName.Text;
int score = Convert.ToInt32(txtScore.Text);
lblScore.Text = "Score : " + Convert.ToString(score);
Session["counter"] = "1";
Random rnd = new Random();
int i = rnd.Next(1, 10);//Here specify your starting slno of question table and ending no.
//lblQuestion.Text = i.ToString();
getQuestion(i);
}
protected void Button2_Click(object sender, EventArgs e)
{
getNextQuestion();
}
public void getQuestion(int no)
{
string str = "select * from [QA] where TestID = " + TestID;
//SqlDataAdapter da2 = new SqlDataAdapter(str, sqlconn);
DataSet ds2 = new DataSet();
//da2.Fill(ds2, "Question");
ds2 = DB.QueryDataSet(str);
if (ds2.Tables[0].Rows.Count > 0)
{
DataRow dtr;
int i = 0;
while (i < ds2.Tables[0].Rows.Count)
{
dtr = ds2.Tables[0].Rows[i];
Session["Answer"] = Convert.ToString(Convert.ToInt32(dtr["Correct"].ToString()) - 1);
Session["Marker"] = dtr["Marker"].ToString();
lblQuestion.Text = "Q." + Session["counter"].ToString() + " " + dtr["Question"].ToString();
RblOption.ClearSelection();
RblOption.Items.Clear();
RblOption.Items.Add(dtr["Option1"].ToString());
RblOption.Items.Add(dtr["Option2"].ToString());
RblOption.Items.Add(dtr["Option3"].ToString());
RblOption.Items.Add(dtr["Option4"].ToString());
i++;
}
}
DB.Close();
getNextQuestion();
}
public void getNextQuestion()
{
if (Convert.ToInt32(Session["counter"].ToString()) < 10)//10 is a counter which is used for 10 questions
{
if (RblOption.SelectedIndex >= 0)
{
if (Session["Answer"].ToString() == RblOption.SelectedIndex.ToString())
{
int score = Convert.ToInt32(txtScore.Text) + 1;// 1 for mark for each question
// txtScore.Text = score.ToString();
lblScore.Text = "Score : " + Convert.ToString(score);
}
else
{
string a = "<script>alert('คุณตอบผิดค่ะ คำอธิบายข้อนี้คือ " + Session["Marker"].ToString() + "')</script>";
Response.Write(a);
}
}
Random rnd = new Random();
int i = rnd.Next(1, 10);
//lblQuestion.Text = i.ToString();
getQuestion(i);
Session["counter"] = Convert.ToString(Convert.ToInt32(Session["counter"].ToString()) + 1);
}
else
{
Panel2.Visible = false;
//code for displaying after completting the exam, if you want to show the result then you can code here.
}
}
}
}
ลืมคะ
|
 |
 |
 |
 |
Date :
2011-03-05 19:13:34 |
By :
เด็กฉลาดน้อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|