if(isset($_GET['submit'])){ for($i=1;$i<=$_GET["hdnLine"];$i++){ $sql = "SELECT * FROM supervision_teacher WHERE loc_id = '".$_GET["loc_id$i"]."' AND per_id = '".$_GET["per_id$i"]."'"; $result = mysql_query($sql); $num = mysql_num_rows($result); if($num > 0){ echo "<script>alert('สถานประกอบการนี้มีอาจารย์ที่เลือกแล้ว');window.location='visionTeacherAdd.php?fav_id=$fav_id';</script>"; exit(); }else{ $sql = "INSERT INTO supervision_teacher (loc_id, per_id)"; $sql .= " VALUES ('".$_GET["loc_id$i"]."','".$_GET["per_id$i"]."')"; $result = mysql_query($sql); } } echo "<script>alert('บันทึกข้อมูลเรียบร้อยแล้ว');window.location='".$_SESSION['visionView']."';</script>"; }
SELECT COUNT(*) AS cnt FROM supervision_teacher WHERE loc_id = 'xxx'
<?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 .= " WHERE fav_id = '$fav_id'"; $result = mysql_query($sql); $show = mysql_fetch_array($result); 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] != ""){ // เงื่อนไข ไม่ให้มีอาจารย์ซ้ำ $sql1 = "SELECT * FROM supervision_teacher WHERE loc_id = '$loc_id' AND per_id = '$per_id'"; $result1 = mysql_query($sql1); $num1 = mysql_num_rows($result1); // เงื่อนไข ไม่ให้มีอาจารย์มากกว่า 3 $sql2 = "SELECT COUNT(loc_id) AS cnt FROM supervision_teacher WHERE loc_id = '$loc_id'"; $result2 = mysql_query($sql2); $show2 = mysql_fetch_array($result2); if($num1 > 0){ echo "<script>alert('สถานประกอบการนี้มีอาจารย์ที่เลือกแล้ว');window.location='visionTeacherAdd.php?fav_id=$fav_id';</script>"; exit(); }else if($show2['cnt'] >= '3'){ echo "<script>alert('สามารถกำหนดอาจารย์ได้สูงสุด 3 ท่านเท่านั้น');window.location='".$_SESSION['visionView']."';</script>"; exit(); }else{ $sql = "INSERT INTO supervision_teacher (loc_id, per_id) VALUES ('$loc_id', '$per_id')"; $result = mysql_query($sql); } } } echo "<script>alert('บันทึกข้อมูลเรียบร้อยแล้ว');window.location='".$_SESSION['visionView']."';</script>"; } ?> <form name="visionViewN" action="<?PHP $_SERVER['PHP_SELF']?>" enctype="multipart/form-data"> <table width="100%" cellpadding="0" cellspacing="1" border="1"> <tr bgcolor="ghostwhite"> <td colspan="2"><b> » จัดการผู้นิเทศก์ : </b><?=$show['loc_name']; if($show['loc_suborder']==""){ echo "<font color=\"gray\"><i>(ไม่มีหนวยงานย่อย)</i></font>";} else { echo " (".$show['loc_suborder'].")"; }?></td> </tr> <tr> <td></td> <td> <select name="per_id[]"> <option value="">ว่าง</option> <?PHP $sqlVis = "SELECT * FROM personnel WHERE cyp_id = '1'"; $sqlVis .= " ORDER BY per_name ASC"; $resultVis = mysql_query($sqlVis); while($showVis = mysql_fetch_array($resultVis)){ ?> <option value="<?=$showVis['per_id']?>"><?=$showVis['per_name']?></option> <?PHP } ?> </select> <input type="hidden" name="loc_id[]" value="<?=$show['loc_id']?>"/> </td> </tr> <tr> <td></td> <td> <select name="per_id[]"> <option value="">ว่าง</option> <?PHP $sqlVis = "SELECT * FROM personnel WHERE cyp_id = '1'"; $sqlVis .= " ORDER BY per_name ASC"; $resultVis = mysql_query($sqlVis); while($showVis = mysql_fetch_array($resultVis)){ ?> <option value="<?=$showVis['per_id']?>"><?=$showVis['per_name']?></option> <?PHP } ?> </select> <input type="hidden" name="loc_id[]" value="<?=$show['loc_id']?>"/> </td> </tr> <tr> <td></td> <td> <select name="per_id[]"> <option value="">ว่าง</option> <?PHP $sqlVis = "SELECT * FROM personnel WHERE cyp_id = '1'"; $sqlVis .= " ORDER BY per_name ASC"; $resultVis = mysql_query($sqlVis); while($showVis = mysql_fetch_array($resultVis)){ ?> <option value="<?=$showVis['per_id']?>"><?=$showVis['per_name']?></option> <?PHP } ?> </select> <input type="hidden" name="loc_id[]" value="<?=$show['loc_id']?>"/> </td> </tr> <tr> <td colspan="2" align="center"> <input type="hidden" name="fav_id" value="<?=$fav_id;?>"/> <input type="submit" name="submit" style="width: 100px" value="บันทึก"/> <input type="button" style="width: 100px" onclick="window.location.href='<? echo $_SESSION['visionView']; ?>'" value="ย้อนกลับ"/> </td> </tr> </table> </form>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง