|
|
|
พี่ๆค่ะช่วยมาดู Codeหน่อยค่ะว่าทำไมติ๊ก Checkall ไปแล้วไม่updateในฐานข้อมูล |
|
|
|
|
|
|
|
สิ่งที่หนูต้องการคือ เมื่อcheck all ไปแล้วจะต้อง update ในฐานข้อมูลจากเดิมที่เป็น 0 จะต้องกลายเป็น 1 ค่ะ พวกพี่ๆใจดีช่วยหน่อยนะค่ะ
enable level 4head]
<?php session_start();?>
<?php require_once('../connection/connect.php'); ?>
<?php require_once('../connection/function.php'); ?>
<?php require_once('../connection/session.php'); ?>
<html><!-- InstanceBegin template="/Templates/index.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Examination Online System</title>
<style type="text/css">
body
{
margin:auto auto auto auto;
}
#left
{
position:fixed;
right:-2px;
width:202px;
}
#right
{
position:fixed;
float:right;
width:770px;
}
.cbg table tr td table tr td #right form table tr td {
text-align: left;
}
</style>
<!-- InstanceEndEditable -->
<meta name="description" content="Education website">
<meta name="keywords" content="education, learning, teaching">
<link href="../css/style.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListCourse(SelectValue)
{
frmMain.ddlCourse.length = 0
frmMain.ddlChapter.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlCourse.options[frmMain.ddlCourse.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM courses ORDER BY courseId ASC ";
//SELECT * FROM tb_subtype ORDER BY id_subtype ASC
$objQuery = mysql_db_query($dbname, $strSQL);
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = "<?=$objResult["facultyId"];?>";
strValue = "<?=$objResult["courseId"];?>";
strItem = "<?=$objResult["courseName"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlCourse.options[frmMain.ddlCourse.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListChapter(SelectValue)
{
frmMain.ddlChapter.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlChapter.options[frmMain.ddlChapter.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM chapters ORDER BY chapterId ASC ";
$objQuery = mysql_db_query($dbname, $strSQL);
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = "<?=$objResult["courseId"];?>";
strValue = "<?=$objResult["chapterId"];?>";
strItem = "<?=$objResult["chapterName"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlChapter.options[frmMain.ddlChapter.length]= myOption
}
<?
}
?>
}
//**** List Amphur (End) ***//
</script>
</head>
<body>
<table width="765" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td height="1"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../images/t1.gif" width="335" height="237"></td>
<td><table width="105%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../images/t2.gif" width="354" height="37"></td>
</tr>
<tr>
<td><img src="../images/t2-5.gif" width="354" height="200"></td>
</tr>
</table></td>
<td><img src="../images/t3.gif" width="330" height="237"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="1"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1"><img src="../images/ml.gif" width="7" height="35"></td>
<td background="../images/mbg.gif" class="bgx"><table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="menu"><a href="#">About Us</a></td>
<td width="1"><img src="../images/msep.gif" width="5" height="35"></td>
<td class="menu"><a href="#">Student Life</a></td>
<td width="1"><img src="../images/msep.gif" width="5" height="35"></td>
<td class="menu"><a href="#">Contact Details</a></td>
</tr>
</table></td>
<td width="1"><img src="../images/mr.gif" width="8" height="35"></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10" height="27" background="../images/cbgl.gif" class="bgy"><img src="../images/cbgl.gif" width="7" height="1"></td>
<td width="1149" class="cbg"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10" height="100%" valign="top"> </td>
<td width="991" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><!-- InstanceBeginEditable name="EditRegion3" -->
<!-- right form -->
<div id="right">
<script language = "JavaScript">
function ListChapter(SelectValue)
{
form2.chapter.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('เลือก','')
form2.chapter.options[form2.chapter.length]= myOption
<?
$intRows = 0;
$sql = "SELECT *,concat(chapterId,' : ',chapterName) FROM chapters ORDER BY chapterId ASC ";
$result = mysql_query($sql) or die ("Error Query [".$sql."]");
$intRows = 0;
while($row = mysql_fetch_array($result))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = '<?=$row["courseId"];?>';
strValue = "<?=$row["chapterId"];?>";
strItem = "<?=$row["chapterName"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
form2.chapter.options[form2.chapter.length]= myOption
}
<?
}
?>
}
</script>
<form name="form2" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
</select>
<table width="100%" height="243" border="0">
<tr>
<td colspan="9">จัดการระดับ</td>
</tr>
<tr>
<td>วิชา</td>
<td colspan="8"><select id="course" name="course" onChange = "ListChapter(this.value)">
<option selected value="">Select</option>
<?
$sql = "SELECT *,concat(courseId,' : ',courseName) as courseIN FROM courses ORDER BY courseId ASC ";
$result = mysql_query($sql) or die ("Error Query [".$sql."]");
while($row = mysql_fetch_array($result))
{
?>
<option value="<?=$row["courseId"];?>">
<?=$row["courseIN"];?>
</option>
<?
}
?>
</select>
</select>
</td>
</tr>
<tr>
<td>รายบท</td>
<td colspan="8">
<select id="chapter" name="chapter">
<option>เลือก</option>
</select>
</tr>
<tr>
<td width="22%">ประเภทสข้อสอบ : </td>
<td colspan="8"> </td>
</tr>
<tr>
<td colspan="9"><table width="100%">
<tr>
<td width="22%"> </td>
<td width="4%"><input type="checkbox" name="Single Choose" id="Single Choose" value="Single Choose" ></td>
<td width="33%">ข้อสอบตัวเลือกข้อเดียว</td>
<td width="4%"><input type="checkbox" name="Multiple Choose" id="Multiple Choose" value="Multiple Choose" ></td>
<td width="37%">ข้อสอบตัวเลือกหลายข้อ</td>
</tr>
<tr>
<td> </td>
<td><input type="checkbox" name="TF" id="TF" value="TF" ></td>
<td>ข้อสอบตัวเลือกถูกผิด</td>
<td><input type="checkbox" name="Describe" id="Describe" value="Describe" ></td>
<td>ข้อสอบประเภทเติมคำ</td>
</tr>
</table></td>
</tr>
<tr>
<td>ระดับความยากง่ายของข้อสอบ</td>
<td width="4%"><input type="checkbox" name="easy" id="easy" value="e" /></td>
<td width="9%">ง่าย</td>
<td width="3%"><input type="checkbox" name="medium" id="medium" value="m" /></td>
<td width="7%">กลาง</td>
<td width="4%"> <input type="checkbox" name="hard" id="hard" value="h" /></td>
<td width="5%">ยาก</td>
<td width="46%" colspan="2"> </td>
</tr>
<tr>
<td height="66" colspan="9"><? $course = $_GET["course"];
$chapter = $_GET["chapter"];
$type = $_GET["typequiz"];
$level = $_GET["level"];
if($type=="-") {$type="%";}
if($level=="-") {$level="%";}?>
<table width="63" align="center">
<tr>
<td><input type="submit" name="button2" id="button2" value="search"></td>
</tr>
</table> <p> </p></td>
</tr>
</table>
</form>
<form name="form1" method="post" action="">
<p>
<? $sql2 = "select count(qid) as countall from quiz_banks where courseId = '$course' and chapterId = '$chapter'";
$result2 = mysql_query($sql2) or exit($sql2);
$row2 = mysql_fetch_array($result2);
$sql3 = "select count(qid) as counttf from quiz_banks where (courseId = '$course' and chapterId = '$chapter') and quiz_type = 'TF'";
$result3 = mysql_query($sql3) or exit($sql3);
$row3 = mysql_fetch_array($result3);
$sql4 = "select count(qid) as countsc from quiz_banks where (courseId = '$course' and chapterId = '$chapter') and quiz_type = 'Single Choose'";
$result4 = mysql_query($sql4) or exit($sql4);
$row4 = mysql_fetch_array($result4);
$sql5 = "select count(qid) as countmc from quiz_banks where (courseId = '$course' and chapterId = '$chapter') and quiz_type = 'Multiple Choose'";
$result5 = mysql_query($sql5) or exit($sql5);
$row5 = mysql_fetch_array($result5);
$sql6 = "select count(qid) as countdc from quiz_banks where (courseId = '$course' and chapterId = '$chapter') and quiz_type = 'Describe'";
$result6 = mysql_query($sql6) or exit($sql6);
$row6 = mysql_fetch_array($result6);
$sql7 = "select count(qid) as counte from quiz_banks where (courseId = '$course' and chapterId = '$chapter') and level = 'e'";
$result7 = mysql_query($sql7) or exit($sql7);
$row7 = mysql_fetch_array($result7);
$sql8 = "select count(qid) as countm from quiz_banks where (courseId = '$course' and chapterId = '$chapter') and level = 'm'";
$result8 = mysql_query($sql8) or exit($sql8);
$row8 = mysql_fetch_array($result8);
$sql9 = "select count(qid) as counth from quiz_banks where (courseId = '$course' and chapterId = '$chapter') and level = 'h'";
$result9 = mysql_query($sql9) or exit($sql9);
$row9 = mysql_fetch_array($result9);
?>
</p>
<table width="630" border="1" align="center">
<tr>
<td width="180">จำนวนคำถามทัังหมด</td>
<td width="28"><input name="numall" type="text" disabled="disabled" id="numall" value="<? echo $row2["countall"]; ?>" size="3" /></td>
<td colspan="6"> </td>
</tr>
<tr>
<td width="180">ประเภทข้อสอบ : TF</td>
<td><input name="numtf" type="text" disabled="disabled" id="numtf" value="<? echo $row3["counttf"]; ?>" size="3" /></td>
<td width="98">Single Choose</td>
<td width="23"><input name="numsc" type="text" disabled="disabled" id="numsc" value="<? echo $row4["countsc"]; ?>" size="3" /></td>
<td width="127">Multiple Choose</td>
<td width="28"><input name="nummc" type="text" disabled="disabled" id="nummc" value="<? echo $row5["countmc"]; ?>" size="3" /></td>
<td width="76">Describe</td>
<td width="18"><input name="numdc" type="text" disabled="disabled" id="numdc" value="<? echo $row6["countdc"]; ?>" size="3" /></td>
</tr>
<tr>
<td>ระดับความยาก : ง่าย</td>
<td><input name="nume" type="text" disabled="disabled" id="nume" value="<? echo $row7["counte"]; ?>" size="3" /></td>
<td width="98">ปานกลาง</td>
<td width="23"><input name="numm" type="text" disabled="disabled" id="numm" value="<? echo $row8["countm"]; ?>" size="3" /></td>
<td width="127">ยาก</td>
<td width="28"><input name="numh" type="text" disabled="disabled" id="numh" value="<? echo $row9["counth"]; ?>" size="3" /></td>
<td width="76"> </td>
<td width="18"> </td>
</tr>
</table>
</form>
<SCRIPT LANGUAGE="JavaScript">
function Check(chk)
{
if(document.myform.Check_all[].checked==true){
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}else{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
}
</script>
<form name="myform" method="post" action="chk_enable_level4.php">
<p>
<?
if($course!= "" and $chapter != "") {
// Search By Name or Email
$sql = "SELECT * FROM quiz_banks where courseId = '$course' and chapterId = '$chapter' and
quiz_type like '$Single' and level like '$easy' or level like '$medium' or level like '$hard'
or quiz_type like '$Multiple' and level like '$easy' or level like '$medium' or level like '$hard'
or quiz_type like '$TF' and level like '$easy' or level like '$medium' or level like '$hard'
or quiz_type like '$Describe' and level like '$easy' or level like '$medium' or level like '$hard'
order by quiz_type ";
$result = mysql_query($sql) or exit($sql);
$Num_Rows = mysql_num_rows($result);
?>
</p>
<table width="100%" border="1">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>
<input type="checkbox" name="Check_all[]" id="Check_all[]" value="yes"onClick="Check(document.myform.Check_ctr)"> <b> อนุญาตทั้งหมด</b>
</td>
</tr>
<tr>
<td width="7%">ลำดับข้อ</td>
<td width="48%">ข้อสอบ</td>
<td width="21%">ประเภท</td>
<td width="9%">ระดับ</td>
<td width="15%"> </td>
</tr>
<?
$i = 0;
while($row = mysql_fetch_array($result))
{
$i++;
?>
<tr>
<td><div align="center"><?=$row["qid"];?></div></td>
<td><?=$row["question_text"];?></td>
<td><?=$row["quiz_type"];?></td>
<td><div align="center"><?php if($row["level"]=="e"){echo "easy";}
else if($row["level"]=="m"){echo "medium";}
else if($row["level"]=="h"){echo "hard";}
?></div></td>
<td><span class="text3">
<?php $sqlz = "select * from quiz_banks where '$enable'=enable ";
$resultz = mysql_query($sqlz) or exit($sqlz);
$rowz = mysql_fetch_array($resultz); ?>
<?php $status = $row["enable"] ?>
<?php
if($status == 1)
{
$checked = 'checked ="checked" ';
}
else{
unset($checked);
}
?>
</span> <input type="checkbox" name="Check_ctr" id="Check_ctr[]<? $i;?>"value= "0"<?=$checked?><?php echo $row['enable']?> ></td>
</tr>
<?
}
?>
</table>
<p>
<input type="hidden" name="hdnCount" id="hiddenField" value="<?=$i;?>">
</p>
</form>
<form name="form3" method="post" action="">
<table width="68" align="center">
<tr>
<td width="60" height="20"><input type="submit" name="button3" id="button3" value="Submit"></td>
</tr>
</table>
</form>
<?php } ?>
<!-- left form -->
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="8" background="../images/cbgr.gif" class="bgy"><img src="../images/cbgr.gif" width="8" height="1"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="1"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../images/bml.gif" width="7" height="24"></td>
<td width="100%" bgcolor="#0C5282" class="bottom-menu">Copyright © 2010 School of Information Technology, King Mongkut's University of Technology Thonburi.</td>
<td><img src="../images/bmr.gif" width="8" height="24"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="1" bgcolor="#1A658C" class="bottom_addr"> </td>
</tr>
</table>
<p> </p>
<div style="position:absolute;left:-30000px;top:-30000px"><a href="http://anvisionwebtemplates.com">Website templates</a><a href="http://cityants.co.uk">Business directory UK</a><a href="http://cityants.net">Yellow pages US</a><a href="http://anvisionwebdesign.com">Website design company</a><a href="http://webdesignfinders.net">Web design directory</a><a href="http://australia.webdesignfinders.net">Web design directory Australia</a><a href="http://canada.webdesignfinders.net">Web design directory Canada</a><a href="http://anvisionwebtemplates.com/free-education-web-templates-layouts.html">Free education web templates</a></div>
</body>
<!-- InstanceEnd --></html>
save ena le
[head]Code (PHP)
<?php
$chk = $_POST['chk[]'];
if(isset($chk) || isset($_POST['Submit'])){
mysql_query ("update quiz_banks set enable = '0'");
foreach($_POST['chk'] as $var){
$result = mysql_query ("update quiz_banks set enable = '1' where qid = '$var'");
if(!$result)
{
echo "แก้ไขข้อมูลผิดพลาด: ", mysql_error();
exit;
}
}
}
?>
<script type="text/javascript">
alert('กำหนดสิทธ์สอบให้นักศึกษาเรียบร้อยแล้ว');
window.location='enable_level4.php';
</script>
Tag : PHP
|
|
|
|
|
|
Date :
2010-09-24 18:36:21 |
By :
pandakuku |
View :
3357 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอไฟล์ทั้งหมดได้ป่ะทาง msn ก็ได้
php และ mysql
[email protected]
|
|
|
|
|
Date :
2010-09-24 21:43:08 |
By :
dekkuza |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทั้งหมดอยู่ในที่ Post อะค่ะ Copy ลงไปเลยค่ะ ส่วนฐานข้อมูลลอง mark ดูนะค่ะ แค่ enable เป็น0 แล้วเปลี่ยนเป็น 1 อย่างเดียวค่ะ
|
ประวัติการแก้ไข 2010-09-24 22:41:39
|
|
|
|
Date :
2010-09-24 22:34:01 |
By :
pandakuku |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หลังจากจ้องอยู่จนลายตาและตาลาย
มันผิดตั้งแต่ตรงนี้แล้ว
<input type="checkbox" name="Check_ctr" id="Check_ctr[]<? $i;?>" value= "0"<?=$checked?><?php echo $row['enable']?> >
ตรงตัวหนาลองเปลี่ยนเป็น chk ดูซิ
ปล. จริงๆ โค๊ดผิดหลายที่นะ ไล่ดูดีๆ
|
|
|
|
|
Date :
2010-09-24 23:07:22 |
By :
PlaKriM |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|