<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style> .border{border-bottom:1px solid #CCC; border-top:1px solid #CCC; padding:5px;} .td{border-bottom:1px solid #CCC; padding-left:7px; padding-top:7px; padding:5px;} </style> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ <?php for($i=0;$i<=4;$i++){?> $("#addRow").click(function(){ var NR =""; NR="<tr>"; NR+="<td width=\"38%\" align=\"center\" class=\"td\">"; NR+="<input name=\"Csubject[]\" type=\"text\" style=\"width:70px; text-align:center;\" value=\"\"/>"; NR+="</td>"; NR+="<td width=\"30%\" align=\"center\" class=\"td\">"; NR+="<input name=\"Credit[]\" type=\"text\" style=\"width:50px; text-align:center;\" value=\"\"/>"; NR+="</td>"; NR+="<td width=\"32%\" align=\"center\" class=\"td\">"; NR+="<input name=\"Grade[]\" type=\"text\" style=\"width:50px; text-align:center;\" value=\"\"/>"; NR+="</td>"; NR+="</tr>"; //$("#myTbl").append($("#firstTr").clone()); $("#myTbl<?php echo $i;?>").append($(NR)); }); $("#removeRow").click(function(){ if($("#myTbl<?php echo $i;?> tr").size()>2){ $("#myTbl<?php echo $i;?> tr:last").remove(); }else{ alert("ต้องมีรายการข้อมูลอย่างน้อย 1 รายการ"); } }); <?php } ?> }); </script> </head> <?php //เชื่อมต่อฐานข้อมูล $db_config=array( "host"=>"localhost", // กำหนด host "user"=>"root", // กำหนดชื่อ user "pass"=>"root", // กำหนดรหัสผ่าน "dbname"=>"course_syllabus", // กำหนดชื่อฐานข้อมูล "charset"=>"utf8" // กำหนด charset ); $mysqli = new mysqli($db_config["host"], $db_config["user"], $db_config["pass"], $db_config["dbname"]); if(mysqli_connect_error()) { die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); exit; } if(!$mysqli->set_charset($db_config["charset"])) { // เปลี่ยน charset เป้น utf8 พร้อมตรวจสอบการเปลี่ยน // printf("Error loading character set utf8: %sn", $mysqli->error); // ถ้าเปลี่ยนไม่ได้ }else{ // printf("Current character set: %sn", $mysqli->character_set_name()); // ถ้าเปลี่ยนได้ } //echo $mysqli->character_set_name(); // แสดง charset เอา comment ออก //echo 'Success... ' . $mysqli->host_info . "n"; //$mysqli->close(); //เชื่อมต่อฐานข้อมูล ?> <body> <form id="form1" name="form1" method="post" action=""> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-left:2%;"> <tr> <td> <?php $sql="select * from category where id_major='2'"; $result = $mysqli->query($sql); // ทำการ query คำสั่ง sql $total=$result->num_rows; // นับจำนวนถวที่แสดง ทั้งหมด $x=0; while($rs=$result->fetch_object()){ // วนลูปแสดงข้อมูล ?> <div style="width:19.8%; height:auto; border:0px solid #000; float:left;"> <table width="100%" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #CCC; font-size:13px"> <tr> <td colspan="3" style="text-align:center; font-weight:800; padding-bottom:10px; padding-top:10px;"><?php echo $rs->name;?></td> </tr> <tr> <td width="37%" align="center" class="border"><strong>วิชา</strong></td> <td width="30%" align="center" class="border"><strong>#</strong></td> <td width="33%" align="center" class="border"><strong>เกรด</strong></td> </tr> <tr> <td colspan="3" style="padding-top:7px;"> <table width="100%" border="0" cellpadding="0" cellspacing="0" style="border:0px solid #CCC;" id="myTbl<?php echo $x;?>"> <?php $sql3="select * from datain_csyllabus where id_category='".$rs->id_category."'"; $result3= $mysqli->query($sql3); // ทำการ query คำสั่ง sql $total3=$result3->num_rows; // นับจำนวนถวที่แสดง ทั้งหมด $row=10; $total=$row-$total3; $i=0; while($rs3=$result3->fetch_array()){ // วนลูปแสดงข้อมูล $i = $i + 1; ?> <tr> <td width="38%" align="center" class="td"><input name="Csubject.<?php echo $rs3['code_subject'];?>[]" type="text" style="width:70px; text-align:center;" value="<?php echo $rs3['code_subject'];?>"/></td> <td width="30%" align="center" class="td"><input name="Credit.<?php echo $rs3['code_subject'];?>[]" type="text" style="width:50px; text-align:center;" value="<?php echo $rs3['credit'];?>" maxlength="1"/></td> <td width="32%" align="center" class="td"><input name="Grade.<?php echo $rs3['code_subject'];?>[]" type="text" style="width:50px; text-align:center;" value="<?php echo $rs3['grade'];?>"/></td> </tr> <?php } ?> </table> </td> </tr> </table> </div> <?php $x++; } ?> </td> </tr> </table> </form> <p><button id="addRow" type="button">เพิ่มแถว</button> <button id="removeRow" type="button">ลบแถว</button> </p> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง