如何从下拉列表中选择值 [英] how to select value from dropdown list

查看:126
本文介绍了如何从下拉列表中选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <  表格   操作  =  search.php    方法  = 发布 >  
<? php
$ select_query = 从书籍中选择不同的类别;
$ select_query_run = mysql_query($ select_query);
$ select_query_array = mysql_fetch_array($ select_query_run);
echo < select name ='类别>中;
while ($ select_query_array = mysql_fetch_array($ select_query_run))
{
// 动态下拉列表和值类似于cat1,cat2,cat3和cat4

echo < option value =''> .htmlspecialchars($ select_query_array [ category])。 < span class =code-string>< / option>
;
}

echo < /选择> 中;
?>
< < input type = text name = searchvalue size = 5 id = searchfield title = searchfield onFocus
= clearText(this) < span class =code-keyword> / >
< 输入 type = 提交 姓名 = 提交 value = alt = 搜索 id = searchbutton title = 搜索 / >
< / form > < < span class =code-keyword>>





SEARCH.PHP

我只是想打印实际用户从drop drown list中选择的值。我尝试下面的代码检查即使我尝试了SESSION但它没有打印任何值,请任何人帮助我。

 <?php  
echo $ _POST [' category'];
?>

解决方案

select_query = 从书籍中选择不同的类别;


select_query_run = mysql_query(


select_query);

<form action="search.php" method="post">
<?php
$select_query=          "Select distinct category from books";
$select_query_run =     mysql_query($select_query);
$select_query_array=   mysql_fetch_array($select_query_run) ;
 echo "<select name='category'>";
while ($select_query_array=   mysql_fetch_array($select_query_run) )
{
//dynamic dropdown list and values are like cat1,cat2,cat3 and cat4

   echo "<option value='' >".htmlspecialchars($select_query_array["category"])."</option>";
}

echo "</select>"; 
 ?>
   <<input type="text" name="searchvalue" size="5"  id="searchfield" title="searchfield" onFocus="clearText(this)"/>
     <input type="submit" name="submit" value="" alt="Search" id="searchbutton" title="Search" />
</form><>



SEARCH.PHP
I am just trying to print what value actually user selected from drop drown list.. I tried below code to check even I tried with SESSION but its not printing any value please anyone help me.

<?php
echo $_POST['category'];
?>

解决方案

select_query= "Select distinct category from books";


select_query_run = mysql_query(


select_query);


这篇关于如何从下拉列表中选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆