selectbox 1选择控件选择框2(但是来自mySQL的数据)

时间:2011-09-19 14:51:14

标签: php mysql sql select drop-down-menu

如何根据选择框1 中选择的内容控制选择框2 的输出?

如果我从选择框1中选择记录1,它将在标题中输出记录1 ID。我想输出选择框2中记录1 ID的所有记录。

如何实现这一点,我的SQL select语句是否不正确?我需要说些什么:

修改 请删除。

$quer=mysql_query("SELECT DISTINCT projectName, projectID 
                   FROM projects 
                   WHERE clientID=$cat 
                   ORDER BY projectName"); 

以上作品。

else { 
  $quer=mysql_query("SELECT DISTINCT projectName, projectID 
                     FROM projects 
                     WHERE projectID = $cat 
                     ORDER BY projectName"); } 

上面不起作用,但我觉得我很近但没有雪茄?

<?php
@$cat=$_GET['cat'];
if(strlen($cat) > 0 and !is_numeric($cat)) {  
  echo "Data Error";
  exit;
}

$quer2 = mysql_query("SELECT DISTINCT clientName,clientID 
                      FROM clients 
                      ORDER BY clientName"); 

if(isset($cat) and strlen($cat) > 0) {
  $quer = mysql_query("SELECT DISTINCT projectName 
                     FROM projects 
                     WHERE projectID = $cat 
                     ORDER BY projectName"); 
} else {
  $quer = mysql_query("SELECT DISTINCT projectName 
                       FROM projects 
                       ORDER BY projectName"); 
}      
echo "<form method=post name=f1 action='dd-check.php'>";

echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while ($noticia2 = mysql_fetch_array($quer2)) { 
  if ($noticia2['clientID'] == @$cat) {
    echo "<option selected value='$noticia2[clientID]'>$noticia2[clientName]</option>"."<BR>";
  } else { 
    echo  "<option value='$noticia2[clientID]'>$noticia2[clientName]</option>";
  }
}
echo "</select>";

echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) { 
  echo  "<option value='$noticia[projectName]'>$noticia[projectName]</option>";
}
echo "</select>";

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

0 个答案:

没有答案