|
 |
|
รบกวนขอโค๊ด PHP แก้ไข แบบเวลาแก้แสดงข้อมูล Checkbox |
|
 |
|
|
 |
 |
|
อยากแก้ไขข้อมูลผ่าน checkbox ค่ะ
โดยตอนนี้สามารถเรียกข้อมูลจาก ตาราง reference_data มาแสดเป็น checkbox ใส่การเพิ่มข้อมูลค่ะ
พอคลิกแก้ไข ก็จะโชว์ข้อมูล เป็น checkbox ที่ดึงมาจากตาราง reference_data
แต่พอคลิกติ๊ก checkbox แก้ไขค่าแล้ว ไปดูในฐานข้อมูล ค่าที่เคยมีอยู่ หายไปหมดเลยค่ะ
รบกวนผู้รู้ช่วยหน่อยค่ะ
ข้อมูลในตาราง reference_data ที่ดึงมาแสดงค่ะ

พอเพิ่มข้อมูลจะนำไปเก็บที่ตาราง university โดย Rf_name ในตาราง university จะเก็บ Rf_ID ของ ตาราง reference_data ในรูปแบบ array ค่ะ

ในส่วนโค้ดที่เขียนไป ก็แบบนี้ค่ะ
ไฟล์ Ad_edit_university
Code (PHP)
<form action="Ad_edit_university_save.php?Univer_ID=<?php echo $_GET['Univer_ID'];?>" name="frmEdit" method="post">
<br/>
<?php
//echo "uni_id=".$_GET['Univer_ID'];
//echo "<br>";
$strSQL = "SELECT university.Univer_ID,university.Univer_name,
uni_type.UniType_ID,university.UniType_ID,university.Rf_name,user.Id_user,
user.Login_user,user.Pw_user,user.Name_user,user.Add_user,
user.Phone_user,user.Email,user.status_user,user.Per_ID
FROM university
LEFT JOIN uni_type ON uni_type.UniType_ID = university.UniType_ID
LEFT JOIN user ON user.Org_ID = university.Univer_ID
WHERE university.Univer_ID ='$Univer_ID' " ;
//echo $strSQL;
$objQuery = mysql_query($strSQL);
//echo $strSQL;
$objResult = mysql_fetch_array($objQuery);
//echo $objResult['Rf_name'];
$rf_list=$objResult['Rf_name'];
//echo $rf_list;
$_array = explode(",",$rf_list);
foreach($_array as $id){
//echo $id;
echo '<br/>';
}
if(!$objResult)
{
echo "Not found =".$_GET['Univer_ID'];
}
else
{
?>
<table align="center" bgcolor="#EDEDED" width="50%" class="table table-bordered table-hover" id="example2">
<tbody>
<tr>
<td bgcolor="#f79e45" width="166" height="18">ชื่อมหาวิทยาลัย</td>
<td bgcolor="#EDEDED" width="669"><input type="text" name="Univer_name" id="Univer_name" size="50" value="<?php echo $objResult['Univer_name'];?>"></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="166" height="18">ประเภทมหาวิทยาลัย</td>
<td bgcolor="#EDEDED" width="669"> <label for="UniType_ID"></label>
<select name="UniType_ID" id="UniType_ID">
<option selected="selected">เลือกรหัสประเภทมหาวิทยาลัย</option>
<option value="1">มหาวิทยาลัยรัฐทั่วไป</option>
<option value="2">มหาวิทยาลัยราชภัฏ</option>
<option value="3">มหาลัยวิทยาลัยราชมงคล</option>
<option value="4">สถาบันเทคโนโลยี</option>
<option value="5">ThaiLis</option>
</select></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="166" height="18">ฐานข้อมูลที่ใช้</td>
<td bgcolor="#EDEDED" width="537">
<p>
<?php
// ส่วนนี้แสดงชื่อฐานข้อมูลมาจากตาราง reference_data
$sql01="select * from reference_data";
$query01=mysql_query($sql01);
// ส่วนนี้วนลูป แสดงค่า RF ทั้งหมดใน ตาราง reference_data ชื่อ checkbox เป็น id
while($rs=mysql_fetch_array($query01)){
?>
<input name="<?php $rs[Rf_ID]; ?>" type="checkbox" id="<?php $rs[Rf_ID];?>" <?php
foreach($_array as $i){
if($i==$rs[Rf_ID]){
echo "checked=\"checked\" ";}}?> value="<?php $rs[Rf_ID]?>" />
<?php
echo $rs[Rf_name]."<br>";
}
?>
</p>
<p>
</p>
<tr>
<td bgcolor="#f79e45" width="150" height="18">เข้าสู่ระบบผู้ใช้</td>
<td bgcolor="#EDEDED" width="400"><input type="text" name="Login_user" id="Login_user" size="50" value="<?php echo $objResult['Login_user'];?>"></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="150" height="18">รหัสผ่านผู้ใช้</td>
<td bgcolor="#EDEDED" width="400"><input type="text" name="Pw_user" id="Pw_user" size="50" value="<?php echo $objResult['Pw_user'];?>"></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="150" height="18">ชื่อผู้ใช้</td>
<td bgcolor="#EDEDED" width="400"><input type="text" name="Name_user" id="Name_user" size="50" value="<?php echo $objResult['Name_user'];?>"></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="150" height="18">ที่อยู่ผู้ใช้</td>
<td bgcolor="#EDEDED" width="400"><input type="text" name="Add_user" id="Add_user" size="50" value="<?php echo $objResult['Add_user'];?>"></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="150" height="18">เบอร์โทรศัพท์</td>
<td bgcolor="#EDEDED" width="400"><input type="text" name="Phone_user" id="Phone_user" size="50" value="<?php echo $objResult['Phone_user'];?>"></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="150" height="18">อีเมล์</td>
<td bgcolor="#EDEDED" width="400"><input type="text" name="Email" id="Email" size="50" value="<?php echo $objResult['Email'];?>"></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="150" height="18">สถานะผู้ใช้</td>
<td bgcolor="#EDEDED"><select name="status_user" id="status_user">
<option value="">เลือกสถานะผู้ใช้</option>
<option value="admin" <?=($_POST['status_user']=="1")?" selected":""?> >admin</option>
<option value="company" <?=($_POST['status_user']=="2")?" selected":""?> >company</option>
<option value="university" <?=($_POST['status_user']=="3")?" selected":""?> >university</option>
<option value="ThaiLis" <?=($_POST['status_user']=="4")?" selected":""?> >ThaiLis</option>
</select></td>
</tr>
<tr>
<td bgcolor="#f79e45" width="150" height="18">สิทธิ์การใช้งานระบบ</td>
<td bgcolor="#EDEDED" ><label for="Per_ID"></label>
<select name="Per_ID" id="Per_ID">
<option selected="selected">เลือกสิทธิ์การใช้งานระบบ</option>
<option value="1">admin</option>
<option value="2">company</option>
<option value="3">university</option>
<option value="4">ThaiLis</option>
</select>
</td>
</tr>
</table>
<tr align="center"><input type="submit" name="submit" value="บันทึก">
<input type="hidden" name = "Univer_ID" value="<?php echo $objResult['Univer_ID'];?>">
<input type="hidden" name="Id_user" value="<?php echo $objResult['Id_user'];?>">
</tr>
<?php
}
?>
</form>
ไฟล์ Ad_edit_university_save
Code (PHP)
<?php
include("connect.php");
$Univer_ID = $_POST['Univer_ID'];
$Univer_name = $_POST['Univer_name'];
$UniType_ID = $_POST['UniType_ID'];
$Rf_name = $_POST['Rf_ID'];
$Id_user = $_POST['Id_user'];
$Login_user = $_POST['Login_user'];
$Pw_user = $_POST['Pw_user'];
$Name_user = $_POST['Name_user'];
$Add_user = $_POST['Add_user'];
$Phone_user = $_POST['Phone_user'];
$Email = $_POST['Email'];
$status_user = $_POST['status_user'];
$Per_ID = $_POST['Per_ID'];
$sql="UPDATE university
SET Univer_name= '$Univer_name',
UniType_ID='$UniType_ID',
Rf_name='$Rf_ID',
Per_ID='$Per_ID'
WHERE Univer_ID = $Univer_ID" ;
$row = mysql_query($sql)or die(mysql_error());
$sql2="UPDATE user
SET Login_user='$Login_user',Pw_user='$Pw_user',
Name_user='$Name_user',Add_user='$Add_user',
Phone_user='$Phone_user',Email='$Email',
status_user='$status_user'
WHERE Id_user=$Id_user";
$row = mysql_query($sql2)or die(mysql_error());
echo ("$sql,$sql2");
/*if($row)
{
$_GET['Univer_ID']=$Univer_ID;
echo $msg ="<script>alert('แก้ไขข้อมูลเรียบร้อย');window.location='show_university.php?';</script>";
//echo "<meta http-equiv='refresh' content='10;URL=show_university.php'>";
}
else
{
echo $msg ="<script>alert('แก้ข้อมูลไม่สำเร็จ');window.location='show_university.php';</script>";
//echo "<meta http-equiv='refresh'content='10;URL=show_university.php'>";
}
echo $sql;
*/
?>
Tag : PHP, HTML/CSS, JavaScript, CakePHP

|
|
 |
 |
 |
 |
Date :
2017-02-19 21:58:26 |
By :
viewsmith |
View :
1827 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
checkbox เขียนแค่นี้ฮะ อย่าไปเขียนเยอะ งง อันไหนไม่เกี่ยวลบออกให้หมด
Ad_edit_university
Code (PHP)
$_array = (array)$objResult['Rf_name']; // รับค่า field แคชเป็น array
<input name="rf[]"
<?php echo in_array($rs['Rf_ID'], $_array) ? 'checked="checked"' : ''; ?> type="checkbox" id="<?php echo $rs['Rf_ID']?>" value="<?php echo $rs[Rf_ID]?>">
<?php echo $rs['Rf_name']."<br>";?>
Ad_edit_university_save
Code (PHP)
$Rf_name = implode(',',$_POST['rf']);
|
ประวัติการแก้ไข 2017-02-20 10:35:49
 |
 |
 |
 |
Date :
2017-02-20 10:29:42 |
By :
Luz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2017-02-21 09:27:06 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|