dongqiao2077
2015-06-24 00:59
浏览 75
已采纳

PHP从下拉列表中获取文本或值

I need a help again.

I need to solve the next problem.

I have to fill one dropdown list from database. If the user select one value, and press the submit button, I have to send the user to the next page, and I should show for all details from this selected value.

Like if the selected value is Monitor, on the next page I have to show the price,and product name and etc in one table.

But I can't figure out how can I get the selected value from this dropdown list and what I should do. This is my code, what is generate my dropdown list and working well.

<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("efszf_a") or die(mysql_error());

$query = "SELECT nev FROM tanulok";
$result = mysql_query($query) or die(mysql_error()."[".$query."]");
?>

<select name="tanulok">
<?php 
while ($row = mysql_fetch_array($result))
{
    echo "<option value=".$row['nev'].">".$row['nev']."</option>";
}
?>        
</select>

Please help me. Regards

图片转代码服务由CSDN问答提供 功能建议

我需要再次提供帮助。

我需要解决下一个问题 。

我必须从数据库中填写一个下拉列表。 如果用户选择一个值,然后按提交按钮,我必须将用户发送到下一页,我应该显示此选定值的所有详细信息。

如果是 选择的值是监视器,在下一页我必须在一个表中显示价格和产品名称等。

但我无法弄清楚如何获得所选值 从这个下拉列表和我应该做什么。 这是我的代码,什么是生成我的下拉列表并运行良好。

 &lt;?php 
mysql_connect(“localhost”  ,“root”,“”)或死(mysql_error()); 
mysql_select_db(“efszf_a”)或死(mysql_error()); 
 
 $ query =“SELECT nev FROM tanulok”; 
 $ result =  mysql_query($ query)或die(mysql_error()。“[”。$ query。“]”); 
?&gt; 
 
&lt; select name =“tanulok”&gt; 
&lt;?php 
while(  $ row = mysql_fetch_array($ result))
 {
 echo“&lt; option value =”。$ row ['nev']。“&gt;”。$ row ['nev']。“&lt; / option&gt;  “; \ N} 
&GT?;  
&lt; / select&gt; 
   
 
 

请帮助我。 Regards

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongpu9852 2015-06-24 01:09
    已采纳

    You need to put your select inside of a form, and have the form submission point to your next page. Like:

    <form action='[yourNextPage.php]' method='post'>
        <select name="tanulok">
        <?php 
        while ($row = mysql_fetch_array($result))
        {
            echo "<option value=".$row['nev'].">".$row['nev']."</option>";
        }
        ?>        
        </select>
        <input type='submit' value='Submit'>
    </form>
    

    Then in your next page, you can access the value the user selected through the $_POST array, like:

    $_POST['tanulok']
    
    点赞 评论
  • douwei9759 2015-06-24 01:04

    Hi if your using post in php you will be able to get the value of the select option by using the select name like this

     $theSelectValue = $_POST['tanulok'];
    
    点赞 评论

相关推荐 更多相似问题