需要将 Session_start() 绑定到 select 语句的更多细节 [英] need more detail tying in Session_start() to a select statement
问题描述
仍然让我头疼,但我认为答案可能会帮助我了解事情的真正运作方式.我的语言总是很烂,但我想在你的帮助下我可以暴力破解.
Still banging my head, but I think an answer may help me see how things really work. I always sucked at languages, but I figure with your help I can brute force this.
所以我只是把整个代码贴出来以免引起混淆.
So I am just going to post the whole code so as not to cause confusion.
<html>
<head>
<title>Change a player</title>
</head>
<BODY >
<?php
include "inc.php";
session_start();
print 'Select week for season: ';
print $this_season;
##the week drop down query#
$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">';
session_start();
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>';
$varWeek=$_POST['Week_select'];
print"</form>";
$_SESSION['week'] = $varWeek;
?>
</body>
</html>
所以,我不知道如何将Week_select"分配给 $_SESSION['week'].上面的代码是我最后的努力.其次,一旦我为 Session 分配了一些东西,我如何在以后清除它以便它不会不断弹出?奖金问题
So, I don't know how to get 'Week_select' to be assigned to $_SESSION['week']. Above code was my last ditch effort. Secondly, once I assign something to the Session, how do I clear it out later so it doesn't keep popping up? Bonus question
print 'Select week for season: ';
print $this_season;
是我可以同时显示语句和变量的唯一方法.当我这样做
Is the only way I can make the both the statement and the variable to display. When I do
print 'Select week for season: '$this_season;
我没有显示变量,当我这样做时也是如此
I don't get the variable displayed, also when I do
print 'Select week for season: $this_season';
我得到了选择周的季节:$this_season 显示
I get Select week for season: $this_season displayed
推荐答案
session_start() 应该放在输出或任何 $_SESSION 交互之前.而且只有一次.
session_start() should be placed before output or any $_SESSION interaction. And only once.
<?php
session_start();
?>
<html>
<head>
<title>Change a player</title>
</head>
<BODY >
<?php
include "inc.php";
// etc...
?>
</body>
</html>
UPDv1:
如果您需要从会话中删除某些内容,则可以执行:
if you need to remove something from session, then you can perform:
<?php unset($_SESSION['something']); ?>
UPDv2:
如果您需要将整个 select 放入 $_SESSION,您可以这样做:
If you need tu put entire select into $_SESSION, you may do:
ob_start();
print "<select name='Week_select'>";
while ($wrow=mysql_fetch_array($wresult))
{ print '<option value="'.$wrow['week_num'].'">week '.$wrow['week_num'].' '.$wrow['week_name'].'</option>'.PHP_EOL; }
print "</select>";
$_SESSION['something'] = ob_get_clean();
// var_dump($_SESSION);
这篇关于需要将 Session_start() 绑定到 select 语句的更多细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!