从分配给变量PHP的下拉列表中获取选择 [英] get a selection from a dropdown list assigned to a variable PHP

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

问题描述

我知道我很简单,但我只是可以找到告诉我如何做的资源。

I know I this is simple, but i just can;t find the resource that tells me how to do it.

所以我的代码如下: / p>

SO my code is as follows:

session_start();
$wquery=
"select week_num,week_name
from stats_week
where season=$this_season
order by week_num";
    $wresult=mysql_query($wquery);


print'<form action="changeplayer_2.php" method="post">';


        print"<select name='Week_select'> <br>";
        while ($wrow=mysql_fetch_array($wresult))
    { 
    print '<option value="'.$wrow['week_num'].'">'.'week '.$wrow['week_num'].'     '.$wrow['week_name'].'</option><br>\n';  
    }

print "</select><br><br>";#

    print'<button type="submit" >Next</button>';


    print"</form>";

所以我做一个选择:
我想要的选择最终在:$ _SESSION ['week']

So I am making a selection: I want that selection to end up in: $_SESSION['week']

推荐答案

内部文件changeplayer_2.php中,您需要将POSTed值加载到会话:

Inside file "changeplayer_2.php" you'll want to load the POSTed value to the session:

session_start();
$_SESSION['week'] = $_POST['Week_select'];

每当你想在关键'周'获得会话的值时,只需执行以下操作:

Whenever you want to get the value of the session at key 'week', simply do:

$ weekValue = isset($ _ SESSION ['week'])? $ _SESSION ['week']:false;

但是,如果您在任何脚本中使用会话变量,请确保您开始会话使用 session_start()

But if you do use the session variable on any script, make sure you start the session using session_start().

要销毁会话变量,您可以执行以下操作:

To destroy the session variable, you can do:

session_start();
unset($_SESSION['week']);

这篇关于从分配给变量PHP的下拉列表中获取选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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