使用PHP的HTML选项字段 [英] Option field in HTML with PHP
问题描述
选择的选项。我的代码如下。
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>< / title>
< / head>
< body>
<?php
包括'Connect.php';
$ query =SELECT varAreaName FROM tbArea;
$ result = mysql_query($ query);
echo'< select name =somename>';
echo'< option value =ANY> - ANY - < / option>';
while($ row = mysql_fetch_assoc($ result)){
echo'< option value =''。$ row ['varAreaName']。'>'。 $ row ['varAreaName']。 < /选项>;
}
echo'< / select>';
?>
< / body>
< / html>
首先,您必须添加表单标记并将表单发布到另一个php脚本中。
您选择的选项将在 $ _ POST
或 $ _ GET
取决于用于发送表单的方法。
示例:
< body>
< form action =your_second_php_script.phpmethod =post>
//您的代码
< / form>
< / body>
并且在 your_second_php_script.php
中:
<?php
var_dump($ _ POST);
?>
如果您需要在原始页面中显示结果,您可以使用ajax来完成工作,但我会从基础开始。
I want to search employee list depend on area name which is selected from dropdown list. I can retrieve names of areas from database into dropdown list from PHP HTML. But now I am confused how to pass selected option in dropdown list to SQL query in PHP. Also I want index numbers of selected options. My code is as follows.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
include 'Connect.php';
$query = "SELECT varAreaName FROM tbArea" ;
$result = mysql_query($query);
echo'<select name="somename">';
echo'<option value="ANY">--ANY--</option>';
while($row = mysql_fetch_assoc( $result )) {
echo '<option value="'.$row['varAreaName'].'">' . $row['varAreaName'] . '</option>';
}
echo '</select>';
?>
</body>
</html>
To start, you would have to add a form tag and post the form to another php script.
Your selected option will be available in either $_POST
or $_GET
depending on the method used to send the form.
Example:
<body>
<form action="your_second_php_script.php" method="post">
// your code
</form>
</body>
And in your_second_php_script.php
:
<?php
var_dump($_POST);
?>
If you need the results to be available in the original page, you can use ajax to get that working, but I would start with the basics.
这篇关于使用PHP的HTML选项字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!