003.
<head>
004.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
005.
<title>Untitled Document</title>
006.
<style>
007.
.border{border-bottom:1px solid #CCC; border-top:1px solid #CCC; padding:5px;}
008.
.td{border-bottom:1px solid #CCC; padding-left:7px; padding-top:7px; padding:5px;}
009.
</style>
010.
012.
<script type=
"text/javascript"
>
013.
$(
function
(){
014.
<?php
for
(
$i
=0;
$i
<=4;
$i
++){?>
015.
$(
"#addRow"
).click(
function
(){
016.
017.
018.
var
NR =
""
;
019.
NR=
"<tr>"
;
020.
NR+=
"<td width=\"38%\" align=\"center\" class=\"td\">"
;
021.
NR+=
"<input name=\"Csubject[]\" type=\"text\" style=\"width:70px; text-align:center;\" value=\"\"/>"
;
022.
NR+=
"</td>"
;
023.
NR+=
"<td width=\"30%\" align=\"center\" class=\"td\">"
;
024.
NR+=
"<input name=\"Credit[]\" type=\"text\" style=\"width:50px; text-align:center;\" value=\"\"/>"
;
025.
NR+=
"</td>"
;
026.
NR+=
"<td width=\"32%\" align=\"center\" class=\"td\">"
;
027.
NR+=
"<input name=\"Grade[]\" type=\"text\" style=\"width:50px; text-align:center;\" value=\"\"/>"
;
028.
NR+=
"</td>"
;
029.
NR+=
"</tr>"
;
030.
031.
032.
033.
$(
"#myTbl<?php echo $i;?>"
).append($(NR));
034.
035.
});
036.
$(
"#removeRow"
).click(
function
(){
037.
if
($(
"#myTbl<?php echo $i;?> tr"
).size()>2){
038.
$(
"#myTbl<?php echo $i;?> tr:last"
).remove();
039.
}
else
{
040.
alert(
"ต้องมีรายการข้อมูลอย่างน้อย 1 รายการ"
);
041.
}
042.
});
043.
<?php } ?>
044.
});
045.
</script>
046.
047.
048.
</head>
049.
<?php
050.
051.
$db_config
=
array
(
052.
"host"
=>
"localhost"
,
053.
"user"
=>
"root"
,
054.
"pass"
=>
"root"
,
055.
"dbname"
=>
"course_syllabus"
,
056.
"charset"
=>
"utf8"
057.
);
058.
$mysqli
=
new
mysqli(
$db_config
[
"host"
],
$db_config
[
"user"
],
$db_config
[
"pass"
],
$db_config
[
"dbname"
]);
059.
if
(mysqli_connect_error()) {
060.
die
(
'Connect Error ('
. mysqli_connect_errno() .
') '
. mysqli_connect_error());
061.
exit
;
062.
}
063.
064.
if
(!
$mysqli
->set_charset(
$db_config
[
"charset"
])) {
065.
066.
}
else
{
067.
068.
}
069.
070.
071.
072.
073.
?>
074.
<body>
075.
<form id=
"form1"
name=
"form1"
method=
"post"
action=
""
>
076.
<table width=
"97%"
border=
"0"
align=
"center"
cellpadding=
"0"
cellspacing=
"0"
style=
"margin-left:2%;"
>
077.
<tr>
078.
<td>
079.
<?php
080.
$sql
=
"select * from category where id_major='2'"
;
081.
$result
=
$mysqli
->query(
$sql
);
082.
$total
=
$result
->num_rows;
083.
$x
=0;
084.
while
(
$rs
=
$result
->fetch_object()){
085.
?>
086.
<div style=
"width:19.8%; height:auto; border:0px solid #000; float:left;"
>
087.
<table width=
"100%"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
style=
"border:1px solid #CCC; font-size:13px"
>
088.
<tr>
089.
<td colspan=
"3"
style=
"text-align:center; font-weight:800; padding-bottom:10px; padding-top:10px;"
><?php
echo
$rs
->name;?></td>
090.
</tr>
091.
<tr>
092.
<td width=
"37%"
align=
"center"
class
=
"border"
><strong>วิชา</strong></td>
093.
<td width=
"30%"
align=
"center"
class
=
"border"
><strong>#</strong></td>
094.
<td width=
"33%"
align=
"center"
class
=
"border"
><strong>เกรด</strong></td>
095.
</tr>
096.
<tr>
097.
<td colspan=
"3"
style=
"padding-top:7px;"
>
098.
099.
100.
<table width=
"100%"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
style=
"border:0px solid #CCC;"
id=
"myTbl<?php echo $x;?>"
>
101.
<?php
102.
$sql3
=
"select * from datain_csyllabus where id_category='"
.
$rs
->id_category.
"'"
;
103.
$result3
=
$mysqli
->query(
$sql3
);
104.
$total3
=
$result3
->num_rows;
105.
$row
=10;
106.
$total
=
$row
-
$total3
;
107.
$i
=0;
108.
109.
while
(
$rs3
=
$result3
->fetch_array()){
110.
111.
$i
=
$i
+ 1;
112.
?>
113.
<tr>
114.
<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>
115.
<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>
116.
<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>
117.
</tr>
118.
<?php } ?>
119.
120.
</table>
121.
</td>
122.
</tr>
123.
</table>
124.
</div>
125.
<?php
$x
++; } ?>
126.
127.
128.
</td>
129.
</tr>
130.
</table>
131.
</form>
132.
133.
<p><button id=
"addRow"
type=
"button"
>เพิ่มแถว</button>
134.
135.
<button id=
"removeRow"
type=
"button"
>ลบแถว</button>
136.
</p>
137.
</body>
138.
</html>