0
我想根据他选择的年份向用户显示选项。 在我有一个函数来获取一年,发回这view2.php同一页面文件的顶部,但我敢肯定,我做错了:根据所选年份显示选项
if(!empty($_POST['year'])){
$year = htmlentities($_POST['year']);
header('Location: view2.php');
//exit();
}
后来,我有一个表格提交,看起来像这样
<form method="post" action="">
Select year:
<?php
$myOptions = array(
'All' => 'All',
'2013' => '2013',
'2014' => '2014',
'2015' => '2015',
'2016' => '2016',
'2017' => '2017',
'2018' => '2018',
'2019' => '2019',
'2020' => '2020'
);
?>
<select name="year">
<?php
foreach($myOptions as $key => $opt) {
$selected = null;
if(isset($_POST['View All']) && $key === $_POST['View All'])
$selected = ' selected';
echo '<option value="' . $key . '"' . $selected. '>' . $opt . '</option>';
}
?>
</select>
<input type="submit" name="submit" value="GO"/>
</form>
如果我手动设置$year
变量,我的SQL查询工作正常年份,因此函数($users->expensePerYear($username, $year, $i);
)是好的。这是我的功能:
<?php
$i=0;
$year = 2013;
//if (isset($year)){
$users->expensePerYear($username, $year, $i);
$userQueryResult = $users->queryResult;
$count = $users->i;
$totalSpent = $users->totalSpent;
$remaining = $budget-$totalSpent;
问题是,我试图发送年份变量到同一页,我做错了。我希望用户在select中指定年份,并将其发送到同一页面并根据该变量显示内容。