2011-02-16 7 views
0

드롭 다운 상자 (MySQL 데이터로 채워짐)와 두 번째 드롭 다운 상자 데이터 (MySQL 데이터로 채워짐)는 첫 번째 드롭 다운 상자와 세 번째 드롭 다운 상자 데이터 (MySQL 데이터로 채워짐)는 두 번째 드롭 다운 상자를 기반으로합니다.내 3 조건부 드롭 다운에서 오류가 발생했습니다

두 개의 드롭 다운을 만들었지 만 세 번째 드롭 다운을 시도했을 때 작동하지 않습니다. 여기에 당신이 여기의 예를 찾을 수 있습니다 내 전체 소스 코드

입니다 : http://www.plus2net.com/php_tutorial/dd3.php

<?php 

require "config.php"; // Your Database details 
?> 

<!doctype html public "-//w3c//dtd html 3.2//en"> 

<html> 

<head> 

<SCRIPT language=JavaScript> 
function reload(form) 
{ 
var val=form.cat.options[form.cat.options.selectedIndex].value; 
self.location='aw.php?cat=' + val ; 
} 
function reload3(form) 
{ 
var val=form.cat.options[form.cat.options.selectedIndex].value; 
var val2=form.subcat.options[form.subcat.options.selectedIndex].value; 

self.location='aw.php?cat=' + val + '&cat3=' + val2 ; 
} 

</script> 
</head> 

<body> 
<? 

///////// Getting the data from Mysql table for first list box////////// 
$quer2=mysql_query("SELECT DISTINCT StudNo,LName,FName,MName,Course FROM students"); 
///////////// End of query for first list box//////////// 

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
$cat=$_GET['cat']; // This line is added to take care if your global variable is off 
if(isset($cat) and strlen($cat) > 0){ 
$quer=mysql_query("SELECT DISTINCT GSCode,GStudNo,GSem,GYear,Grade FROM grade WHERE GStudNo='$cat' order by GSCode"); 
}else{$quer=mysql_query("SELECT DISTINCT GSCode,GStudNo,GSem,GYear,Grade FROM grade order by GSCode"); } 
////////// end of query for second subcategory drop down list box /////////////////////////// 
$quer2=mysql_query("SELECT DISTINCT GSCode,GStudNo,GSem,GYear,Grade FROM grade"); 

/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// 
$cat3=$_GET['subcat']; // This line is added to take care if your global variable is off 
if(isset($cat3) and strlen($cat3) > 0){ 
$quer3=mysql_query("SELECT DISTINCT GSem,GYear,Grade FROM grade where GSCode='$cat3'"); 
}else{$quer3=mysql_query("SELECT DISTINCT GSem,GYear,Grade FROM grade"); } 
////////// end of query for third subcategory drop down list box /////////////////////////// 


echo "<form method=post name=f1 action='dd3ck.php'>"; 
//////////  Starting of first drop downlist ///////// 
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; 
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['StudNo'][email protected]$cat){echo "<option selected value='$noticia2[StudNo]'>$noticia2[StudNo]</option>"."<BR>";} 
else{echo "<option value='$noticia2[StudNo]'>$noticia2[StudNo]</option>";} 
} 
echo "</select>"; 
////////////////// This will end the first drop down list /////////// 

//////////  Starting of second drop downlist ///////// 
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>"; 
while($noticia = mysql_fetch_array($quer)) { 
if(empty($noticia['Grade']) AND $noticia['GSCode'][email protected]$cat3){echo "<option selected value='$noticia[GSCode]'>$noticia[GSCode]</option>"."<BR>";} 
else{echo "<option value='$noticia[GSCode]'>$noticia[GSCode]</option>";} 
} 
echo "</select>"; 
////////////////// This will end the second drop down list /////////// 


//////////  Starting of third drop downlist ///////// 
echo "<select name='subcat3' ><option value=''>Select one</option>"; 
while($noticia = mysql_fetch_array($quer3)) { 
echo "<option value='$noticia[GSem]'>$noticia[GSem]</option>"; 
} 
echo "</select>"; 
////////////////// This will end the third drop down list /////////// 


echo "<input type=submit value='Submit the form data'></form>"; 
?> 

</body> 

</html 

>

답변

0

그 코드가 상당히 지저분하다, 더 리턴은 확인되지 않습니다. SQL 주입 방지.

$cat3=$_GET['subcat']; 

가 작동

$cat3=$_GET['cat3']; 
+0

들으해야한다 : 언뜻

나는 당신의 라인을 믿습니다! 하지만 그것은 빈 기능이 2 차 선택에서 작동하지 않는 것 같습니다. – PiDO

+0

당신은 그것이 작동하지 않는다고 어떻게 생각합니까? – Jacob

+0

나는 그것이 작동하고있는 것을 의미한다. 그러나 그것이 내가 그것이 만든 2 개의 드롭 다운에서 작동하는 방식과 같기를 원하는 방식으로 작동하지 않는 것처럼 보인다. 그것은 비어 있지 않은 레코드조차도 모든 레코드를 보여준다. 나는 2 드롭 다운에서 사용하는 것과 동일한 코드를 사용하지만 다르게 작동합니다. – PiDO

관련 문제