ถามเรื่องตัวแปร $$ch ไม่สามารถใช้งานได้เวลาอัพขึ้น server คะ
ลอง $$ch คือการเอาค่าตัวแปรของ $ch มาเป้นตัวแปรอีกครั้งหนึ่ง ลองตรวจสอบค่าดูก่อนน่ะครับ ว่ามันถูกต้องหรือไม่
Date :
2010-12-11 19:48:37
By :
webmaster
random.php
<?
session_start();
if($_SESSION[username]=="")
{
?>
<script type="text/javascript">
window.location="../index.php"
</script>
<?
}
$id_type=$_GET[id_type];
if($id_type==1){
$type="ก่อนเรียน";
}else{
$type="หลังเรียน";
}
include('../connect/connect.php');
$sql="select * from student where username_stu='$_SESSION[username]' ";
$result=mysql_db_query($dbname,$sql);
$res=mysql_fetch_array($result);
$idstu_auto=$res[idstu_auto];
$username=$res[username_stu];
$password=$res[password_stu];
$title_stu=$res[title_stu];
$name_stu=$res[name_stu];
$lname_stu=$res[lname_stu];
?>
<!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=windows-874" />
<title>::แบบทดสอบ<?php echo $type ?>::</title>
<STYLE type=text/css>
A:link {COLOR: #000000; TEXT-DECORATION: none}
A:visited {COLOR: #000000; TEXT-DECORATION: none}
A:hover {COLOR: #000000; TEXT-DECORATION: underline}
</STYLE>
<style type="text/css">
<!--
body {
background-color: #EDEBED;
}
.style1 {color: #FFFFFF}
.style6 {font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #000000; }
.style7 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
}
.style8 {font-size: 16px}
-->
</style>
</head>
<body>
<table width="874" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center"><img src="../teacher/photo/b1.png" width="874" height="155" /></div></td>
</tr>
</table>
<table width="874" height="66" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr bgcolor="#CCCCCC">
<td width="836" height="22" bgcolor="#999999"><span class="style7"> <a href="index.php">หน้าแรก</a> <span class="style1">|</span> <a href="logout.php">ออกจากระบบ</a></span></td>
</tr>
<tr>
<td height="22" background="../checklogin/pic/top_cover.jpg"> </td>
</tr>
</table>
<table width="874" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF"> </td>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF" class="style6">ยินต้อนรับคุณ <?php echo $name_stu." ".$lname_stu; ?>เข้าสู่ระบบจัดกิจกรรมใบงานแบบปรับเปลี่ยน</td>
</tr>
<tr>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF"> </td>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF" class="style6"> </td>
</tr>
<tr>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF"> </td>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF" class="style6"><div align="center" class="style8">แบบทดสอบ<?php echo $type ?></div></td>
</tr>
<tr>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF"> </td>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF" class="style7"><FORM METHOD="POST" ACTION="check_test.php">
<p>
<span class="style7">
<?
$number=1;
include "../connect/connect.php";
$sql="select * from test where test.id_type='$id_type' order by rand() limit 0,5";
$result=mysql_db_query("$dbname",$sql);
while ($r=mysql_fetch_array($result)) {
$id=$r[id];
$question=$r[question];
$pic_q=$r[pic_q];
$choice1=$r[choice1];
$pic_c1=$r[pic_c1];
$choice2=$r[choice2];
$pic_c2=$r[pic_c2];
$choice3=$r[choice3];
$pic_c3=$r[pic_c3];
$choice4=$r[choice4];
$pic_c4=$r[pic_c4];
$answer=$r[answer];
$i++;
?>
<?php echo"<b>ข้อ $number:</b><br>"."$question<br>";?>
<?
if($pic_q!="")
{
?>
<img src="../teacher/test/q1/<?=$pic_q;?>" />
<?
}
?>
</span>
<p>
<table width="97%" height="140" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="27" valign="top"><div align="left" class="style7">
<input name="select_<?=$id;?>" type="radio" value="1" />
</div></td>
<td width="39" valign="top"><div align="left">
<span class="style7">
ก. </span></div></td>
<td width="728"><div align="left">
<span class="style7">
<?
if($pic_c1!="")
{
?>
<img src="../teacher/test/c1/<?=$pic_c1;?>" />
<?
}else{
?>
<?php echo "$choice1";
}
?> </span></div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style7">
<input name="select_<?=$id;?>" type="radio" value="2" />
</div></td>
<td valign="top"><div align="left">
<span class="style7">
ข. </span></div></td>
<td><div align="left">
<span class="style7">
<?
if($pic_c2!="")
{
?>
<img src="../teacher/test/c2/<?=$pic_c2;?>" />
<?
}else{
?>
<?php echo "$choice2";
}
?></span></div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style7">
<input name="select_<?=$id;?>" type="radio" value="3" />
</div></td>
<td valign="top"><div align="left">
<span class="style7">
ค. </span></div></td>
<td><div align="left">
<span class="style7">
<?
if($pic_c3!="")
{
?>
<img src="../teacher/test/c3/<?=$pic_c3;?>" />
<?
}else{
?>
<?php echo "$choice3";
}
?> </span></div></td>
</tr>
<tr>
<td height="35" valign="top"><div align="left" class="style7">
<input name="select_<?=$id;?>" type="radio" value="4" />
</div></td>
<td valign="top"><div align="left">
<span class="style7">
ง. </span></div></td>
<td><div align="left">
<span class="style7">
<?
if($pic_c4!="")
{
?>
<img src="../teacher/test/c4/<?=$pic_c4;?>" />
<?
}else{
?>
<?php echo "$choice4";
}
?> </span></div></td>
</tr>
</table>
<p>
<span class="style7">
<br />
<BR>
<input type='hidden' name='idstu_auto' value='<?php echo $idstu_auto?>' />
<BR>
<input name="id_type" type="hidden" id="id_type" value="<?=$id_type;?>" />
<input name="total_question[]" type="hidden" value="<?=$id;?>" />
<BR>
</span></p>
<HR>
<?php
$number++;
}
?>
<INPUT TYPE="submit" VALUE="Submit"><INPUT TYPE="reset" VALUE="Reset">
</FORM></td>
</tr>
<tr>
<td width="55" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> </td>
<td width="819" bordercolor="#FFFFFF" bgcolor="#FFFFFF" class="style7"> </td>
</tr>
</table>
<table width="874" height="135" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="1" align="center" valign="top" bgcolor="#FFFFFF"><img src="../images/span_pic.gif" width="1" height="5" hspace="0" /></td>
<td align="center" valign="top" background="../teacher/photo/bg_content_bt.jpg"><p> </p></td>
<td width="1" valign="top" bgcolor="#FFFFFF"><img src="../images/span_pic.gif" width="1" height="10" hspace="0" /></td>
</tr>
</table>
<table width="874" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="1"><img src="../teacher/photo/main_m3.gif" width="20" height="20" /></td>
<td background="../teacher/photo/main_bot_bg.gif"> </td>
<td width="1"><img src="../teacher/photo/main_m4.gif" width="20" height="20" /></td>
</tr>
</table>
</body>
</html>
เป็นเว็บสำหรับสุ่มข้อสอบและส่งค่าไปยังไฟล์ check_test.php
check_test.php
<?php
session_start();
if($_SESSION[username]=="")
{
?>
<script type="text/javascript">
window.location="../index.php"
</script>
<?
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<?
$id_stu=$_POST[idstu_auto];
$id_type=$_POST[id_type];
$total_question=$_POST[total_question];
$total=count($total_question);
$correct=0;
include('../connect/connect.php');
$sql="select id,answer from 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 "คะแนนของคุณคือ $correct คะแนน <BR>จากข้อสอบทั้งหมด $total ข้อ";
if($id_type=="1"){
$sql = "UPDATE student SET pretest = '$correct' WHERE idstu_auto = '$id_stu' ";
}else{
$sql = "UPDATE student SET posttest = '$correct',status_pass='Y' WHERE idstu_auto = '$id_stu' ";
}
$result=mysql_db_query($dbname,$sql);
?>
<style type="text/css">
<!--
.style1 {font-size: 14}
-->
</style>
<a href="../index.php" class="style1">กรุณารอการอนุมัติจากอาจารย์</a>
เป็นหน้าสำหรับตรวจข้อสอบคะ เวลารันใน localhost ใช้ได้ปกตินะคะแต่พอขึ้น server มันไม่คำนวณ $correctคะ คิดว่าน่าจะมาจาการโพส radio คะ เพราะหน้านี้ไม่ได้ $_POST ไว้ เนื่องจากไม่รู้จะ POST ยังไงเพราะอีกหน้าที่ radio ตั้งชื่อว่า <input name="select_<?=$id;?>" type="radio" value="4" /> แบบนี้คะไม่รู้จะแก้ไขยังไงคะ รบกวนผู้รู้ช่วยด้วยนะคะ
Date :
2010-12-12 11:09:25
By :
froggy_piggy
Load balance : Server 04