|
 |
|
มีปัญหาในการแก้ไขข้อมูลจาก CheckBox รบกวนดูให้ทีครับ |
|
 |
|
|
 |
 |
|
ปัญหาคือผลจำการดึงข้อมูลข้อมูมาแล้วใช้ CheckBox ทำการแก้ไขค่าลงไปไหม่ในอีกตาราง
แต่แถวที่ผมไม่ได้ติ๊ก กลับถูกบันทึกไหม่กลายเป็นค่าว่างๆ ส่วนแถวที่ติดก็มีการบันทึกข้อมูลได้ปกติ
อยากจะให้แถมที่ไม่ได้ติ้ก ไม่มีการบันทึกข้อมูลต้องทำไงหรอครับ
อันนี้โค้ด หน้าที่ ที่จะแก้ไขข้อมูล
Code (PHP)
if(empty($YEAR))
{echo "<script>alert('กรุณากรอกข้อมูลให้ครบด้วย');</script>";
echo "<script>window.location='SearchUnfitAddEdit.php'</script>";}
else{
$YEAR = $_REQUEST['YEAR'];}
if(empty($COURSEID)){
echo "<script>alert('กรุณากรอกข้อมูลให้ครบด้วย');</script>";
echo "<script>window.location='SearchUnfitAddEdit.php'</script>";}
else{
$COURSEID = $_REQUEST['COURSEID'];}
if(empty($SECTORID)){
echo "<script>alert('กรุณากรอกข้อมูลให้ครบด้วย');</script>";
echo "<script>window.location='SearchUnfitAddEdit.php'</script>";}
else{
$SECTORID = $_REQUEST['SECTORID'];}
if(empty($TEACHERID)){
echo "<script>alert('กรุณากรอกข้อมูลให้ครบด้วย');</script>";
echo "<script>window.location='SearchUnfitAddEdit.php'</script>";}
else{$TEACHERID = $_REQUEST['TEACHERID'];}
$a="หมดสิทธิ์สอบ";
$b="มีสิทธิ์สอบ";
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("ge");
$objDB = mysql_query("SET NAMES 'utf8'");
$strSQL = "SELECT
property.ID,
property.`YEAR`,
property.SECTORID,
sector.SECTORNAME,
property.COURSEID,
cur_regcourse.COURSENAME,
property.TEACHERID,
teacher.TEACHERNAME,
property.STUDENTID,
studen.STUDENTNAME,
property.INELIGIBLE
FROM
property
Inner Join teacher ON teacher.TEACHERID = property.TEACHERID
Inner Join studen ON studen.STUDENTID = property.STUDENTID
Inner Join sector ON sector.SECTORID = property.SECTORID
Inner Join cur_regcourse ON cur_regcourse.COURSEID = property.COURSEID
WHERE
property.YEAR='$YEAR' AND
property.COURSEID='$COURSEID' AND
property.SECTORID='$SECTORID' AND
property.TEACHERID='$TEACHERID' AND
property.INELIGIBLE='$a' AND
property.INELIGIBLE!='$b'
";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form action="UfitAddEditSave.php" name="frmEdit" method="post">
<?
$strSQL .=" order by STUDENTID ASC LIMIT $Page_Start , $Per_Page";//
$objQuery = mysql_query($strSQL);
?>
<table width="97%" border="0" align="center">
<tr>
<td><h3 align="center">ยกเลิกสถาณะ หมดสิทธิ์สอบ ของนักศึกษา</h3></td>
</tr>
<tr>
<td>
<table width="100%" border="1">
<tr>
<th > <div align="center">รหัสนักศึกษา </div></th>
<th > <div align="center">ชื่อ - นามสกุล </div></th>
<th >กำหนดสถานะ</th>
</tr>
<?
$i =0;
while($data = mysql_fetch_array($objQuery))
{ $i=$i+1;
?>
<tr>
<td><div align="center"><input type="hidden" name="ID<?=$i;?>" size="5" value="<?=$data["ID"];?>"><?=$data["STUDENTID"];?></div></td>
<td><?=$data["STUDENTNAME"];?></td>
<td><div align="center">
<input name="chkUnfit<?=$i;?>" type="checkbox" value="มีสิทธิ์สอบ" <? if($data["INELIGIBLE"]=="มีสิทธิ์สอบ"){echo"checked";} ?> />
มีสิทธิ์สอบ</div> </td>
</tr>
<?
}
?>
</table>
<?
if($Num_Rows<=0){
$error= "ไม่พบข้อมูล";}
?>
<table width="97%" cellspacing="0">
<tr>
<td width="100%"><div align="center"><?=$error?></div></td>
</tr>
<tr>
<td width="100%"><div align="center">
<input name="submit" type="submit" value="submit"/>
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</div></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
อันนี้โค้ดสำหรับบันทึกข้อมูล
Code (PHP)
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("ge");
$objDB = mysql_query("SET NAMES 'utf8'");
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
$strSQL = "UPDATE property SET ";
$strSQL .="INELIGIBLE = '".$_POST["chkUnfit$i"]."' ";
$strSQL .="WHERE ID = '".$_POST["ID$i"]."' ";
$objQuery = mysql_query($strSQL);
}
echo "สถาณะได้ถูกบันทึกแล้ว";
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2012-03-13 15:35:04 |
By :
motoko |
View :
939 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองงี้มั้ยครับ
Code (PHP)
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("ge");
$objDB = mysql_query("SET NAMES 'utf8'");
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
if(isset($_POST["chkUnfit$i"]) and !empty($_POST["chkUnfit$i"])) {
$strSQL = "UPDATE property SET ";
$strSQL .="INELIGIBLE = '".$_POST["chkUnfit$i"]."' ";
$strSQL .="WHERE ID = '".$_POST["ID$i"]."' ";
$objQuery = mysql_query($strSQL);
}
}
echo "สถาณะได้ถูกบันทึกแล้ว";
?>
ลองดูนะ
|
 |
 |
 |
 |
Date :
2012-03-13 16:35:51 |
By :
kenessar |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ล่ะครับ ของคุณมากครับ
|
 |
 |
 |
 |
Date :
2012-03-13 17:16:31 |
By :
motoko |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|