  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                Code (PHP) 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script language = "JavaScript">
		//**** List Subject (Start) ***//
		function ListSubject(SelectValue)
		{
			frmMain.ddlSubject.length = 0
			
			//*** Insert null Default Value ***//
			var myOption = new Option('','')  
			frmMain.ddlSubject.options[frmMain.ddlSubject.length]= myOption
			
			<?
			$sql_year="select t.term,y.yID,t.termID from term t inner join years y on t.yID=y.yID order by t.termID desc limit 1";
			$query_year=mysql_query($sql_year);
			$rs_year=mysql_fetch_array($query_year);
			$yID=$rs_year['yID'];
			$termID=$rs_year['termID'];
			$term=$rs_year['term'];
			
			
			$intRows = 0;
			$strSQL = "select * from teach t inner join subject s on t.sbjID=s.sbjID where t.termID='$termID' ";
			$objQuery = mysql_query($strSQL);
			$intRows = 0;
			while($objResult = mysql_fetch_array($objQuery))
			{
			$intRows++;
			?>			
				x = <?php echo $intRows;?>;
				mySubList = new Array();
				
				strGroup = <?php echo $objResult['teacherID'];?>;
				strValue = "<?php echo $objResult['sbjID'];?>";
				strItem = "<?php echo $objResult['subject'];?>";
				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])  
					frmMain.ddlSubject.options[frmMain.ddlSubject.length]= myOption					
				}
			<?
			}
			?>																	
		}
		//**** List Subject (End) ***//
</script>
</head>
<body>
<form name="frmMain" action="" method="post">
	ครูผู้สอน 
	<select id="ddlTeacher" name="ddlTeacher" onChange = "ListSubject(this.value)">
	<option selected value=""></option>
	<?
	$strSQL = "select * from teacher";
	$objQuery = mysql_query($strSQL);
	while($objResult = mysql_fetch_array($objQuery))
	{
	?>
	<option value="<?php echo $objResult['teacherID'];?>"><?php echo $objResult['name'];?></option>
	<?
	}
	?>
	</select>
	วิชา
	<select id="ddlSubject" name="ddlSubject" style="width:120px" ></select>
</form>
</body>
</html>
 
 
  Tag : PHP, MySQL, JavaScript               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2011-12-05 15:07:02 | 
                      By :
                          ubu1984 | 
                      View :
                          1205 | 
                      Reply :
                          4 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |