คือว่าผมเว็บอีเลิร์นและได้สร้างข้อสอบมา แล้วอยากจะให้มัน เชื่อมต่อกับฐานข้อมูลเว็บครับ และโชว์ ชื่อ - นามสกุล ในตารางข้อมูล member ของผมครับ
นี่คือโค้ดข้อสอบนะครับ
<?php require_once('Connections/elearn.php'); ?>
<?php
$colname_Recordset1 = "-1";
if (isset($_GET['idl'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['idl'] : addslashes($_GET['idl']);
}
mysql_select_db($database_elearn, $elearn);
$query_Recordset1 = sprintf("SELECT * FROM tb_test WHERE idl = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $elearn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>[url=http://www.kakarndee.com]www.kakarndee.com[/url]</title>
<style type="text/css">
<!--
body,td,th {
font-family: Microsoft Sans Serif;
font-size: small;
}
a {
font-family: Microsoft Sans Serif;
font-size: small;
}
h1,h2,h3,h4,h5,h6 {
font-family: Microsoft Sans Serif;
border: 1;
}
body {
background-color: #FFFFFF;
margin-top: 0px;
margin-bottom: 0px;
background-image: url(../images/body.jpg);
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.borderG {
border: 2px dotted #FF0000;
}
.borderB {
border: 2px dotted #0000FF;
}
.borderG {
border: 1px dotted #0000FF;
}
.borderB {
border: 1px dotted #FF0000;
}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i ) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i )
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j ].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p 1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i ) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i ) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i =3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j ]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i 2];}
}
//-->
</script>
<style type="text/css" media="all">
<!--
@import url("12.css");
.style1 {
color: #FF0000;
font-weight: bold;
}
.style3 {font-size: 36px}
.style4 {color: #FF0000}
-->
</style>
</head>
<body onload="MM_preloadImages('../moom/images1/Untitled-1_01.gif','moom/images1/Untitled-1_02.gif','moom/images1/Untitled-1_03.gif','moom/images1/Untitled-1_04.gif','moom/images1/Untitled-1_05.gif','moom/images1/Untitled-1_06.gif','moom/images1/Untitled-1_07.gif')">
<span class="style3"></span>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="lo">
<!--DWLayoutTable-->
<tr>
<td width="780" height="180" valign="top"><img src="../images/head2.png" width="728" height="200" /></td>
</tr>
<tr valign="middle">
<td height="16" align="center" valign="top"><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image20','','moom/images1/Untitled-1_01.gif',1)"></a><a href="uppic/boardpic.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image21','','moom/images1/Untitled-1_02.gif',1)"></a><a href="Board/webboard.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image22','','moom/images1/Untitled-1_03.gif',1)"></a><a href="kguest.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image23','','moom/images1/Untitled-1_04.gif',1)"></a><a href="kmsn.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image24','','moom/images1/Untitled-1_05.gif',1)"></a><a href="Download.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image25','','moom/images1/Untitled-1_06.gif',1)"></a><a href="kadmin.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image26','','moom/images1/Untitled-1_07.gif',1)"></a><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','../moom/images1/Untitled-1_01.gif',1)"><strong>
<?php $correct=0;
$total=0;
include "connect.php";
$sql="select id, answer from tb_test where idl='1' order by id";
$result=mysql_db_query("$dbname",$sql);
$total=mysql_num_rows($result);
while ($r=mysql_fetch_array($result)){
$id=$r[id];
$answer=$r[answer];
$select="select_".$id;
if(${$select}==$answer) {
$correct ;
}
}
echo "แบบทดสอบทั้งหมด $total ข้อ ";
?>
</strong></a></td>
</tr>
<tr>
<td height="135" valign="top"><table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="65"> </td>
<td width="620"> </td>
<td width="65"> </td>
</tr>
<tr>
<td height="25"> </td>
<td> <img src="../images/admin/pin.gif" width="16" height="16" /> คำชี้แจง กรุณากรอกข้อมูลนักศึกษาให้ครบก่อน แล้ว จงเลือกคำตอบที่ถูกที่สุดเพียงข้อเดียว <br />
นำคะแนนที่ได้แค่ครั้งแรกครั้งเดียวเท่านั้นไปเป็นคะแนนจริง ดูตาม เวลาที่นักศึกษาได้ทำการส่งคะแนน กำหนดเวลาแค่ <span class="style1">30</span> นาที ในการส่งคะแนน <span class="style4">ระบบจะจัดส่งคะแนนเองอัตโนมัติเมื่อหมดเวลาในการทำข้อสอบ <br />
<br />
<br />
</span></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><form action="Atest2.php" method="post" name="form1" id="form1">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">ชื่อ</td>
<td><input name="name" type="text" id="name" />
<span class="style4">***</span></td>
<td align="center">นามสกุล</td>
<td><input name="lname" type="text" id="lname" /> <span class="style4">***</span></td>
</tr>
<tr>
<td align="center">แผนก</td>
<td><input name="class" type="text" id="class" />
<span class="style4">***</span></td>
<td align="center">รหัสประจำตัวนักศึกษา</td>
<td><input name="on" type="text" id="on" />
<span class="style4">*****</span></td>
</tr>
<tr>
<td align="center">ปีการศึกษา</td>
<td><input name="pee" type="text" id="pee" /></td>
<td> </td>
<td><input name="etc" type="hidden" id="etc" value="ปลายภาค" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<?php
$number=1;
include "connect.php";
$sql="select * from tb_test where idl='1' order by id";
$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 <br> ";
$number ;
}
?><br />
<input type="submit" name="Submit" value="ส่งคะแนน" />
<input type="submit" name="Submit2" value="ยกเลิก" />
</form>
<br /></td>
<td> </td>
</tr>
</table>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td align="center"><strong>
<?php $correct=0;
$total=0;
include "connect.php";
$sql="select id, answer from tb_test where idl='1' order by id";
$result=mysql_db_query("$dbname",$sql);
$total=mysql_num_rows($result);
while ($r=mysql_fetch_array($result)){
$id=$r[id];
$answer=$r[answer];
$select="select_".$id;
if(${$select}==$answer) {
$correct ;
}
}
echo "
แบบทดสอบทั้งหมด $total ข้อ ";
?>
</strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td align="center">ตรวจสอบข้อมูลให้ถูกต้องทุกครั้งก่อนส่งคะแนนด้วยนะคับ</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="32" valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
</table>
<div align="center"></div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
ผมจะต้องเพิ่มโค้ดใดบ้างในการเชื่อมต่ออีกครับ เพื่อที่จะให้มันโชว์ ชื่อ - นามสกุล ในตารางข้อมูล member ของผมครับ
ขอบคุณล่วงหน้าครับ
