|
 |
|
เช็คข้อมูลใน list box แบบหลายอัน โดยจะต้องไม่ซ้ำกัน |
|
 |
|
|
 |
 |
|
ลองดู jquery อะครับ น่าจะทำได้ง่ายขึ้น
|
 |
 |
 |
 |
Date :
2014-06-07 18:01:08 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองเขียนมาให้มันดูง่ายขึ้นนะครับ หรือมันเป็นแบบใหม่เลยหรือป่าวไม่รู้ครับ
เวลา insert เป็นแบบนี้ครับ
insert เป็นแบบ ดังรูปครับ

กรอกค่าลงไปเลยในช่องแรก กรอกลงไป 13 14 15
ใน db ก็จะได้ ประมาณนี้ครับ
id per loc
1 13 60
2 14 60
3 15 60
แล้วพอจะ update อ่ะครับ จะทำยังไงให้มัน ขึ้นมาใน ช่องที่กรอกแบบตอน insert ครับ
ที่ทำมันออกมา แบบนี้เลยอ่ะครับ

ในช่องแรกต้องเป็น
13
14
15
แต่ถ้าหากตอน Insert กรอกลงไป แค่ 2 record
ในช่องแรกต้องเป็น
13
14
ช่องสุดท้ายที่ไม่กรอกก็ปล่อยให้ว่างไว้อ่ะครับ (แต่ต้องทีช่องให้กรอกทั้ง 3 record เพื่อจะได้เพิ่มได้ สุงสุดยังไงก็ไม่เกิน 3
หน้าแสดงข้อมูลเป็นแบบนี้นะครับ ใช้ group_concat
มันจะแสดงแบบนี้ครับ
________________________________
60 | 13, 14, 15 | [ ปุ่ม INSERT + UPDATE]
แล้วเดี๋ยวตอนเช็คก็มาเช็ค ว่าช่องที่กรอกลงไปมันมีค่าซ้ำกันหรือป่าว
Code (PHP)
<?PHP
include "config/connect.php";
// รับค่าที่ส่งมา
$fav_id = $_GET['fav_id'];
$sql = "SELECT * FROM favor";
$sql .= " LEFT JOIN location ON favor.loc_id = location.loc_id";
$sql .= " LEFT JOIN supervision_teacher ON supervision_teacher.loc_id = location.loc_id";
$sql .= " LEFT JOIN personnel ON supervision_teacher.per_id = personnel.per_id";
$sql .= " WHERE fav_id = '$fav_id'";
$result = mysql_query($sql);
$show = mysql_fetch_array($result);
?>
<form name="form1" action="<?PHP $_SERVER['PHP_SELF']?>" enctype="multipart/form-data">
<table width="100%" cellpadding="0" cellspacing="1">
<tr>
<td>
<input type="text" name="per_id[]" value="<?=$show['per_id']?>"/>
<input type="text" name="loc_id[]" value="<?=$show['loc_id']?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="per_id[]" value="<?=$show['per_id']?>"/>
<input type="text" name="loc_id[]" value="<?=$show['loc_id']?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="per_id[]" value="<?=$show['per_id']?>"/>
<input type="text" name="loc_id[]" value="<?=$show['loc_id']?>"/>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="บันทึก"/>
</td>
</tr>
</table>
</form>
<?PHP
// Insert
if(isset($_GET['submit'])){
for($i=0;$i<count($_GET["per_id"]);$i++){
$per_id = $_GET["per_id"][$i];
$loc_id = $_GET["loc_id"][$i];
if($_GET["per_id"][$i] != ""){
$sql = "INSERT INTO supervision_teacher (loc_id, per_id) VALUES ('$loc_id', '$per_id')";
$result = mysql_query($sql);
}
}
echo "<script>alert('บันทึกข้อมูลเรียบร้อยแล้ว');window.location='visionViewN.php?selDuration=$selDuration';</script>";
}
?>
|
ประวัติการแก้ไข 2014-06-08 15:05:10 2014-06-08 15:09:17 2014-06-08 15:10:08 2014-06-08 15:10:49 2014-06-08 15:14:45 2014-06-08 15:23:19
 |
 |
 |
 |
Date :
2014-06-08 15:04:25 |
By :
sabaitip |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|