|
 |
|
dropdownlist menu แบบ 2 ชั้น ระดับสองข้อมูลหายค่ะ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
mysql_select_db($database_Conn, $Conn);
$query_RecordsetDegree = "SELECT * FROM degree";
$RecordsetDegree = mysql_query($query_RecordsetDegree, $Conn) or die(mysql_error());
$row_RecordsetDegree = mysql_fetch_assoc($RecordsetDegree);
$totalRows_RecordsetDegree = mysql_num_rows($RecordsetDegree);
mysql_select_db($database_Conn, $Conn);
$query_RecordsetRoom = "SELECT * FROM room";
$RecordsetRoom = mysql_query($query_RecordsetRoom, $Conn) or die(mysql_error());
$row_RecordsetRoom = mysql_fetch_assoc($RecordsetRoom);
$totalRows_RecordsetRoom = mysql_num_rows($RecordsetRoom);
?>
<script language = "JavaScript">
function ListRoom(SelectValue)
{
form1.RoomID.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
form1.RoomID.options[form1.RoomID.length]= myOption
<?php
$intRows = 0;
while ($row_RecordsetRoom = mysql_fetch_assoc($RecordsetRoom))
{
$intRows++;
?>
x = <?php echo $intRows; ?>;
mySubList = new Array();
strGroup = <?php echo $row_RecordsetRoom['DegreeID']; ?>;
strValue = "<?php echo $row_RecordsetRoom['RoomID']; ?>";
strItem = "<?php echo $row_RecordsetRoom['RoomName']; ?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
form1.RoomID.options[form1.RoomID.length]= myOption
}
<?php
}
?>
}
</script>
<table>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ระดับชั้น:</td>
<td><select name="DegreeID" onChange="ListRoom(this.value)">
<option selected value=""></option>
<?php
do {
?>
<option value="<?php echo $row_RecordsetDegree['DegreeID']?>"><?php echo $row_RecordsetDegree['DegreeName']?></option>
<?php
} while ($row_RecordsetDegree = mysql_fetch_assoc($RecordsetDegree));
$rows = mysql_num_rows($RecordsetDegree);
if($rows > 0) {
mysql_data_seek($RecordsetDegree, 0);
$row_RecordsetDegree = mysql_fetch_assoc($RecordsetDegree);
}
?>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ห้องเรียน:</td>
<td><select name="RoomID" id="RoomID"></select></td>
</tr>
</table>
ข้อมูลระดับชั้น
DegreeID DegreeName
1 ม.1
2 ม.2
3 ม.3
้ข้อมูลห้องเรียน
RoomID DegreeID RoomName
1 1 ม.1/1
2 1 ม.1/2
3 1 ม.1/3
4 2 ม.2/1
5 2 ม.2/2
6 2 ม.2/3
เลือกระดับชั้นแล้ว ห้องเรียนจะมา
ปัญหาคือ ระดับชั้น ม1 ห้องเรียนขึ้นแค่ ม.1/2 ม.1/3
แต่ถ้าเลือก ม.2 ห้องเรียนมาครบ ทั้ง 2/1 2/2 2/3
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2014-05-11 21:17:30 |
By :
noona |
View :
1958 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง View Source ในหน้า Web Browser ดูครับ จะรู้ว่าข้อมูลไหนที่ไม่มา สังเตกุตรง JavaScript ที่ไม่ถูก Generate มาให้ครับ 
|
 |
 |
 |
 |
Date :
2014-05-12 09:22:58 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|