我在用PHP代码编写的for
循环中有3个下拉列表。
<?php
for ($u=1;$u<=$slot;++$u){
$y=$u-1;
++$uu;
echo "PR: <SELECT name='prog[$uu]' id='prog{$uu}'><option></option>";
$az1=mysql_query("select distinct Programme from details");
while ($az2=mysql_fetch_array($az1)){
echo "<option >$az2[Programme]</option>";
}
echo "</select>";
echo "CR: <SELECT name='course[$uu]' id='course{$uu}' ><option></option>";
$az1=mysql_query("select distinct Course from details order by Course");
while ($az2=mysql_fetch_array($az1))
{
echo "<option >$az2[Course]</option>";
}
echo "</select> ";
echo "CO: <SELECT name='counsellor[$uu]' id='counsellor{$uu}' ><option></option>";
$az1a=mysql_query("select distinct Counsellor from counsellor");
while ($az2a=mysql_fetch_array($az1a)){
echo "<option >$az2a[Counsellor]</option>";
}
echo "</select>";
}
?>
我想让它们依赖,以便CR
取决于PR
和CO
取决于CR
。
请帮帮我。
我对for
循环感到困惑。在没有for
循环的情况下,我使用了
<script type="text/javascript">
$(function(){
var $cat6 = $("#cat6"),
$subcat6 = $("#subcat6");
$cat6.on("change",function(){
var _rel = $(this).val();
$subcat6.find("option").attr("style","");
$subcat6.val("");
if(!_rel) return $subcat6.prop("disabled",true);
$subcat6.find("[rel="+_rel+"]").show();
$subcat6.prop("disabled",false);
});
});
$(function(){
var $cat6 = $("#cat6"),
$subcat7 = $("#subcat7");
$cat6.on("change",function(){
var _rel = $(this).val();
$subcat7.find("option").attr("style","");
$subcat7.val("");
if(!_rel) return $subcat7.prop("disabled",true);
$subcat7.find("[rel="+_rel+"]").show();
$subcat7.prop("disabled",false);
});
});
</script>
</head>
</html>
<?php
echo "<form action='sc4b.php' method='post' target='_blank'>";
echo "PROGRAMME: <SELECT name='prog' id='cat6' required><option>
</option>
<OPTGROUP LABEL='Bachelor Degree Programme'>
<option>BDP</option><option>BSW</option><option>BCA</option>
<option>BTS</option>
</OPTGROUP>
<OPTGROUP LABEL='Master Degree Programme'>
<option>MEG</option><option>MPS</option><option>MAEDU</option>
<option>M.Com</option>
<option>MAPY</option><option>MAH</option><option>MSW</option>
<option>MEC</option>
<option>MARD</option><option>MSO</option>
</OPTGROUP></select>";
echo "COURSE: <SELECT name='course' id='subcat6' required><option>
</option>";
$az1=mysql_query("select * from details");
while ($az2=mysql_fetch_array($az1))
{
echo "<option rel='$az2[Programme]'>$az2[Course]</option>";
}
echo "</select>";
echo "COUNSELLOR: <SELECT name='counsellor' id='subcat7' required>
<option></option> ";
$az1a=mysql_query("select * from counsellor");
while ($az2a=mysql_fetch_array($az1a))
{
echo "<option rel='$az2a[Programme]'>$az2a[Counsellor]</option>";
}
echo "</select>";
我想知道如何修改此代码,以便解决for
循环问题。没有for
循环名称和id是以下形式
name='name' id='id'
但在for循环中它是
name='name[$i]' id='id{$i}'
我很困惑如何在jquery脚本中包含$i
。