English 中文(简体)
能否从同一档案中的一份下级清单中找到某些选择的价值?
原标题:Get the value of selected option from a dropdown list in the same file in php?

I have 2 drop down list, one is college and other is branch, so what i want to do is that whenever a user selects a college from the first drop down list, the script should automatically check for the branches available in that college and should add them to the second drop down list i.e. of branches, currently I am doing it manually.

<?php
mysql_connect("localhost", "root", "") or die("Connection Failed");
mysql_select_db("pet")or die("Connection Failed");
$query = "SELECT distinct insti_name FROM maininfo";
$result = mysql_query($query);




$query2 = "SELECT distinct insti_name FROM maininfo";
$result2 = mysql_query($query2);

?>
<form name="myform" id="one" method="post" action="compare.php">
Select first college: 
<select name="coll1">
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line[ insti_name ];?>"> <?php echo $line[ insti_name ];?>
</option>

<?php
}
?>
</select>
<br /><p>Select the branch:


<select name="brn1">

<option value="0" selected>(please select:)</option>
<option value="ce">Civil</option>
<option value="cse">Computer Science Engineering</option>
<option value="ec">Electronics and Communication</option>
<option value="it">Information Technology</option>
<option value="aeie">AEIE</option>
<option value="mech">Mechanical</option>
<option value="elect elex">Elect Elex</option>
<option value="ee">Electricals</option>
<option value="el">EL</option>
<option value="chem">Chemical</option>
<option value="fire">Fire</option>
<option value="ei">ei</option>
<option value="food">Food</option>
<option value="ip">Information Practises</option>
<option value="bt">Bio Technology</option>

</select>


<br>
<hr width=100% height=4>

Select second college: 
<select name="coll2">
<?php
while ($line = mysql_fetch_array($result2, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line[ insti_name ];?>"> <?php echo $line[ insti_name ];?>
</option>

<?php
}
?>


</select>


<br /><p>Select the branch:
<select name="brn2">
<option value="0" selected>(please select:)</option>
<option value="ce">Civil</option>
<option value="cse">Computer Science Engineering</option>
<option value="ec">Electronics and Communication</option>
<option value="it">Information Technology</option>
<option value="aeie">AEIE</option>
<option value="mech">Mechanical</option>
<option value="elect elex">Elect Elex</option>
<option value="ee">Electricals</option>
<option value="el">EL</option>
<option value="chem">Chemical</option>
<option value="fire">Fire</option>
<option value="ei">ei</option>
<option value="food">Food</option>
<option value="ip">Information Practises</option>
<option value="bt">Bio Technology</option>

</select>
<br><br>
<input type="submit" name="Submit" value="Compare Colleges" >
</form>
最佳回答

作为一个说明,如果与阿富汗复兴开发银行合作的话,这更有利于用户。 然而,你需要确定你的形式,在更换你的学院选箱时提交。 之后,在您的《公共卫生法》中,你需要:

if( isset( $_POST[ coll1 ] ) ) {
    //query your branches and populate select same as you did for colleges.
    //e.g. "SELECT * FROM Branches WHERE CollegeId=".mysql_real_escape_string($_POST[ coll1 ]);
}

这是否足以使你从中获益?

问题回答

Remember the distinction between the PHP (running on the server) and the client (which is where things like Javascript will run).

你们想要的是两种方法之一: 首先,你可以预先为某个特定学院提供的所有分支,而对于客户来说,如果改变一个学院,就可以执行一个文字,从而改变所介绍的分支。 请注意,这涉及提前让所有大学的分支部门参加。

第二,你可以有一则书,在大学变更时,可以询问所支持的分支的服务器,并更改所介绍的分支。 这种方法要求处理得少得多,通常称为“非洲复兴开发银行”解决办法。

请注意,这两种方式都涉及撰写一些 Java文,供客户根据学院的变化进行操作。

我试图回答。

If you re willing to use JavaScript, then take a look at jQuery, in particular,
http://api.jquery.com/change/
Otherwise to do it with PHP, as far as I know, you d have to submit a form and refresh the page. Which probably isn t what you want. You could use PHP/ajax/json, but if you could do that you may as well use JavaScript directly.
jQuery should make it easy, there s probably even a dedicated plugin.

比如,你要么必须实施自动协调机制,积极更新该网页,要么必须把“col”价值重新贴在你的网页上。 (在此坐下来打字,刚刚张贴了三个新的答案......) ......根据该学院安排你的数据库。

如果你的名单是巨大的,我将使用亚克斯。

如果没有的话,你就可以在 Java文中预设一个阵列,并修改<代码>onchange上的选项。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签